Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: close streams gracefully #1864

Merged
merged 1 commit into from
Jul 20, 2023
Merged

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Jul 3, 2023

  • Refactors .close, closeRead and .closeWrite methods on the Stream interface to be async
  • The Connection interface now has .close and .abort methods
  • .close on Streams and Connections wait for the internal message queues to empty before closing
  • .abort on Streams and Connections close the underlying stream immediately and discards any unsent data
  • .reset is removed from the Stream interface - instead call .abort(err) to signal a local error
  • .reset is still present on the AbstractStream class - the muxer implementation should call this to signal a remote error
  • @chainsafe/libp2p-yamux now uses the AbstractStream class from @libp2p/interface the same as @libp2p/mplex and @libp2p/webrtc - all the logic around the *checks notes* 17 different ways to close a stream is contained there

Follow-up PRs will be necessary to @chainsafe/libp2p-yamux, @chainsafe/libp2p-gossipsub and @chainsafe/libp2p-noise though they will not block the release as their code is temporarily added to this repo to let CI run.

Fixes #1793
Fixes #656

BREAKING CHANGE: the .close, closeRead and closeWrite methods on the Stream interface are now asynchronous

- [License](#license)
- [Contribution](#contribution)

## Install
## Usage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is helpful information but I think it would be more appropriate to open a PR against test plan's README since that repo is responsible for this workflow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the audiences are different.

The README in this repo is useful for people who want to run the tests with their local copy of js-libp2p+changes against release versions of other libp2p implementations and is what the usage examples have in mind.

The users of the test plan repo are a little less well defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that if someone wants to test their js-libp2p changes against other libp2p implementation versions, they would follow a pattern similar to the one utilized here and run the changes following the README

Copy link
Member Author

@achingbrain achingbrain Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find the documentation in the test plans repo to be sufficient to actually run the tests locally; a number of extra steps were required.

Perhaps we can consolidate these in a future PR.

interop/package.json Outdated Show resolved Hide resolved
interop/test/ping.spec.ts Outdated Show resolved Hide resolved
@maschad
Copy link
Member

maschad commented Jul 5, 2023

I assume we had to the encryption libraries here as well for a similar reason to #1856 (comment) ?

@achingbrain
Copy link
Member Author

I assume we had to the encryption libraries here as well for a similar reason to #1856 (comment) ?

Yes, that's correct - they'll be removed after release.

Base automatically changed from feat/merge-stat-properties to master July 20, 2023 11:12
@achingbrain achingbrain force-pushed the fix/close-streams-gracefully branch 3 times, most recently from a4d77b5 to e1e55d3 Compare July 20, 2023 11:38
- Refactors `.close`, `closeRead` and `.closeWrite` methods on the `Stream` interface to be async
- The `Connection` interface now has `.close` and `.abort` methods
- `.close` on `Stream`s and `Connection`s wait for the internal message queues to empty before closing
- `.abort` on `Stream`s and `Connection`s close the underlying stream immediately and discards any unsent data
- `@chainsafe/libp2p-yamux` now uses the `AbstractStream` class from `@libp2p/interface` the same as `@libp2p/mplex` and
`@libp2p/webrtc`

Follow-up PRs will be necessary to `@chainsafe/libp2p-yamux`, `@chainsafe/libp2p-gossipsub` and `@chainsafe/libp2p-noise`
though they will not block the release as their code is temporarily added to this repo to let CI run.

Fixes #1793
Fixes #656

BREAKING CHANGE: the `.close`, `closeRead` and `closeWrite` methods on the `Stream` interface are now asynchronous
@achingbrain achingbrain merged commit b36ec7f into master Jul 20, 2023
17 checks passed
@achingbrain achingbrain deleted the fix/close-streams-gracefully branch July 20, 2023 14:12
This was referenced Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanly closing streams Full stream close guarantee
2 participants