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

Immediate remote closes are not reported #211

Open
pimterry opened this issue Dec 18, 2023 · 1 comment
Open

Immediate remote closes are not reported #211

pimterry opened this issue Dec 18, 2023 · 1 comment

Comments

@pimterry
Copy link
Contributor

I don't have a minimal repo yet, but I have an existing test that passes in NDC 0.4.3 and fails in 0.5.1+.

The issue seems to be this part of the test:

dataChannel.addEventListener('open', () => dataChannel.close());

This is the browser side of the connection, using WebRTC from within Chrome, which creates a data channel, and then immediately closes it once it opens. On the server side, using NDC it subscribes to onClosed event synchronously after the onDataChannel event fires, which I'd expect to mean we do receive every close event.

With previous NDC versions, the above code always fired onClosed() on the NDC side, as expected. In 0.5.1+ it never does - no close event is ever fired on the NDC channel.

channel.isOpen() behaves inconsistently (50/50 true/false) when called initially immediately within the channel creation callback (this by itself is fine, given the setup that's not super surprising). It always returns false 100ms later, but even in the cases where it goes from true to false it still doesn't call the callback (registered synchronously at the same time as checking isOpen).

Interestingly, the test does pass, and the callback is called if a small timeout is used on the browser side, like so:

dataChannel.addEventListener('open', () => setTimeout(() => dataChannel.close(), 10));

I assume that means there's some kind of race condition with registering the close callback somewhere, either here or libdatachannel. I'd totally understand if the channel was just always created with isOpen false initially in this case, but being inconsistently open and never firing the event is hard to handle nicely.

Does that make sense? Any idea what might have caused this? Let me know if you need more detail and I can try to put together a cleaner repro, but I'm hoping you might have an idea of where this has come from already.

@paullouisageneau
Copy link
Contributor

Thank you for reporting. In this situation, the wrapper sets the onClosed callback late (after the actual event) as onDataChannel is scheduled on the event loop instead of running synchronously. This should be handled by libdatachannel which should trigger the callback anyway but there might be a race condition when doing so. I'm investigating.

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

No branches or pull requests

2 participants