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(@libp2p/webrtc): delay closing datachannels #2048

Closed
wants to merge 2 commits into from

Conversation

achingbrain
Copy link
Member

Tactical fix until we can update the spec to coordinate closing datachannels.

Calling .close on a datachannel causes a stream reset - depending on the implementation there's a good chance any data waiting to be transmitted will be lost.

As a workaround when closing a datachannel wait until it's .bufferedAmount property is 0, then wait a bit longer before closing the channel.

This is because although Firefox will have sent all the data by this point, Chrome may have not.

This should be removed when the spec is updated.

Refs: libp2p/specs#575

Tactical fix until we can update the spec to coordinate closing
datachannels.

Calling `.close` on a datachannel causes a stream reset - depending
on the implementation there's a good chance any data waiting to
be transmitted will be lost.

As a workaround when closing a datachannel wait until it's
`.bufferedAmount` property is `0`, then wait a bit longer before
closing the channel.

This is because although Firefox will have sent all the data by
this point, Chrome may have not.

This should be removed when the spec is updated.
@achingbrain achingbrain requested a review from a team as a code owner September 13, 2023 14:21
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Looks good, I have two questions. Also I do wonder how frequently this is happening, do you think it would make sense to instrument this to measure that?

packages/transport-webrtc/src/muxer.ts Show resolved Hide resolved
packages/transport-webrtc/src/util.ts Show resolved Hide resolved
@achingbrain
Copy link
Member Author

I do wonder how frequently this is happening

Pretty frequently, it turns out. It's what causes this kind of CI failure.

@maschad
Copy link
Member

maschad commented Sep 13, 2023

Pretty frequently, it turns out. It's what causes this kind of CI failure.

Have you ran that test a few times on CI to ensure that this fix solves it?

@maschad maschad marked this pull request as draft September 19, 2023 16:02
@maschad
Copy link
Member

maschad commented Sep 19, 2023

As discussed in triage, this may actually be an issue with Chrome, @achingbrain will file a report.

Update: Report filed https://bugs.chromium.org/p/chromium/issues/detail?id=1484907

@maschad
Copy link
Member

maschad commented Sep 21, 2023

@achingbrainI I am re-opening this as it will unblock CI without us having to skip the test entirely, until https://bugs.chromium.org/p/chromium/issues/detail?id=1484907 is resolved.

@maschad maschad marked this pull request as ready for review September 21, 2023 18:22
@maschad
Copy link
Member

maschad commented Oct 1, 2023

Closing in favour of #2073

@maschad maschad closed this Oct 1, 2023
achingbrain added a commit that referenced this pull request Oct 6, 2023
- Gracefully close streams on muxer shutdown
- Refactor initiator/recipient flows for clarity
- Wait for `bufferedAmount` to be `0` before closing a datachannel
- Close datachannels on both initiator and recipient
- Implements FIN_ACK for closing datachannels without data loss

Supersedes #2048

---------

Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
achingbrain added a commit that referenced this pull request Oct 6, 2023
- Gracefully close streams on muxer shutdown
- Refactor initiator/recipient flows for clarity
- Wait for `bufferedAmount` to be `0` before closing a datachannel
- Close datachannels on both initiator and recipient
- Implements FIN_ACK for closing datachannels without data loss

Supersedes #2048

---------

Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
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.

2 participants