Add a timeout to check if datachannel opened

This is similar to the deadlock bug in the proxy-go instances. If the
proxy-pair sends an answer to the broker, it previously assumed that the
datachannel would be opened and the pair reused only once the
datachannel closed. However, sometimes the datachannel never opens due
to ICE errors or a misbehaving/buggy client causing the proxy to
infinitely loop and the proxy-pair to remain active.

This commit reuses the pair.running attribute to indicate whether or not
the datachannel has been opened and sets a timeout to close the
proxy-pair if it has not been opened by that time.
This commit is contained in:
Cecylia Bocovich 2019-07-24 10:52:33 -04:00
parent 6cc944f2b4
commit e77baabdcf
2 changed files with 11 additions and 3 deletions

View file

@ -74,10 +74,16 @@ class Snowflake {
this.ui.setStatus(msg);
recv = this.broker.getClientOffer(pair.id);
recv.then((desc) => {
if (pair.running) {
if (pair.active) {
if (!this.receiveOffer(pair, desc)) {
return pair.active = false;
}
//set a timeout for channel creation
return setTimeout((() => {
log('proxypair datachannel timed out waiting for open');
pair.close();
return pair.active = false;
}), 20000); // 20 second timeout
} else {
return pair.active = false;
}