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

@ -85,6 +85,7 @@ class ProxyPair {
prepareDataChannel(channel) {
channel.onopen = () => {
log('WebRTC DataChannel opened!');
this.running = true;
snowflake.state = Snowflake.MODE.WEBRTC_READY;
snowflake.ui.setActive(true);
// This is the point when the WebRTC datachannel is done, so the next step
@ -176,7 +177,6 @@ class ProxyPair {
clearTimeout(this.timer);
this.timer = 0;
}
this.running = false;
if (this.webrtcIsReady()) {
this.client.close();
}
@ -186,6 +186,8 @@ class ProxyPair {
}
this.relay = null;
this.onCleanup();
this.active = false;
this.running = false;
}
flush() {
@ -245,7 +247,7 @@ ProxyPair.prototype.relay = null; // websocket
ProxyPair.prototype.timer = 0;
ProxyPair.prototype.running = true;
ProxyPair.prototype.running = false; // Whether a datachannel is opened
ProxyPair.prototype.active = false; // Whether serving a client.