node-datachannel icon indicating copy to clipboard operation
node-datachannel copied to clipboard

addIceCandidate is blocking the event-loop

Open Aviv1000 opened this issue 1 year ago • 7 comments

In my case there are times when it blocks the running of the entire node program sometimes for over 10 seconds. I discovered that the blocking of the event-loop comes from addIceCandidate and there may also be a block from setLocalDescription and setRemoteDescription I use polyfill to be compatible with the browser API, but I don't think it has anything to do with it.

i think maybe its happen when the remote candidate contains an IPv6 address. { candidate: 'candidate:995260933 1 udp 1677732095 ce81:ce81:ce81:ce81:ce81:ce81:ce81:ce81 54885 typ srflx raddr :: rport 0 generation 0 ufrag 5s6n network-cost 999', sdpMLineIndex: 0, sdpMid: '0' }

Is this a bug in node-datachannel or can it be handled through my code only? What is the technical reason for the problem?

Aviv1000 avatar Aug 25 '24 11:08 Aviv1000

I think it could be caused by the libjuice issue reported in https://github.com/paullouisageneau/libjuice/discussions/264: if DNS resolution for ICE servers fails, subsequent ICE calls for the same peer connection could block due to incorrect locking. It was fixed by https://github.com/paullouisageneau/libjuice/pull/267 and will be shipped alongside the next libdatachannel version.

paullouisageneau avatar Aug 26 '24 10:08 paullouisageneau

But this happens specifically when adding this remote candidate. he dont need to deal with DNS resolution. Maybe it's because of invalid port number 0? raddr :: rport 0 (chrome browser generated this candidate like this to the nodejs)

Aviv1000 avatar Aug 26 '24 17:08 Aviv1000

But this happens specifically when adding this remote candidate. he dont need to deal with DNS resolution.

The issue could make ICE calls block, in particular setting remote description and candidates, because the ICE agent held a lock while resolving STUN/TURN servers in parallel which can take a while, especially in case of DNS failure.

Maybe it's because of invalid port number 0? raddr :: rport 0 (chrome browser generated this candidate like this to the nodejs)

This is fine, raddr and rport are allowed to be 0.

paullouisageneau avatar Aug 27 '24 22:08 paullouisageneau

hi, last update v0.12.0 of node-datachannel seem that still not fix the issue.

Aviv1000 avatar Sep 30 '24 22:09 Aviv1000

any news about it?

Aviv1000 avatar Oct 19 '24 12:10 Aviv1000

Hello,

I'm still waiting for the next release of libdatachannel.

murat-dogan avatar Oct 19 '24 19:10 murat-dogan

New version released here https://github.com/murat-dogan/node-datachannel/releases/tag/v0.20.0

Thank you for your patience!

murat-dogan avatar Oct 25 '24 18:10 murat-dogan

New version released here https://github.com/murat-dogan/node-datachannel/releases/tag/v0.20.0

Thank you for your patience!

thank you very much and also for libdatachannel's team, i will check the new version and let you know if everything is working well.

Aviv1000 avatar Oct 26 '24 23:10 Aviv1000

unfortunately, seem like still in some cases addIceCandidate blocking the event-loop, but much less then before.

Aviv1000 avatar Dec 24 '24 02:12 Aviv1000

@Aviv1000 I can't reproduce. Do you have example code leading to addIceCandidate() blocking?

paullouisageneau avatar Dec 27 '24 17:12 paullouisageneau

maybe was other problem in my code, until now i haven't seen blocking for a long time. I think it can be mark it as solved and closed. Thanks everyone 💯

Aviv1000 avatar Mar 02 '25 12:03 Aviv1000