paullouisageneau / libdatachannel

C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets
https://libdatachannel.org/
Mozilla Public License 2.0
1.81k stars 366 forks source link

DTLS Handshake is really slow with Firefox #155

Closed stazio closed 4 years ago

stazio commented 4 years ago

Hi @paullouisageneau, As the title suggests, I am noticing a long delay between the initialization of the DTLS transport, and the completion of the DTLS handshake. It can take upwards of 15 seconds or more to establish said connection (sometimes even timing out). Do you have any idea why this is? I have also disabled all of my media stuff and tried using master.

paullouisageneau commented 4 years ago

Is it with OpenSSL as backend? I think this is linked to the unsolved issue in https://github.com/paullouisageneau/libdatachannel/issues/58

stazio commented 4 years ago

It is happening with GNuTLS as well.

paullouisageneau commented 4 years ago

OK, I'm looking into it.

stazio commented 4 years ago

It is definitely some kind of race condition. I had to refactor a bunch of my code and it stopped happening. So, I guess it's okay now?

paullouisageneau commented 4 years ago

The issues seems to appear only when libdatachannel is offering. In that case, libdatachannel takes the controlling ICE role, and even if it selects a working network pair quickly, it seems Firefox waits for a pair to be actually nominated. This can take some time if there is unluckily a non-working higher-priority pair, because the timeout is pretty long in libjuice. I'll fix it by making the nomination more aggressive.