GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 41009639 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Close stale connection

If we stop getting keep-alive pings for some timeout period, close the
stale connection. This solves bug #31278 where chrome proxies hang open
on an idle connection.
parent c0b6d25e
......@@ -31,6 +31,9 @@ Config.prototype.pollAdjustment = 300.0 * 1000;
// Timeout after sending answer before datachannel is opened
Config.prototype.datachannelTimeout = 20 * 1000;
// Timeout to close proxypair if no messages are sent
Config.prototype.messageTimeout = 30 * 1000;
Config.prototype.maxNumClients = 1;
Config.prototype.proxyType = "";
......
......@@ -16,7 +16,7 @@ class ProxyPair {
- @relayAddr is the destination relay
- @rateLimit specifies a rate limit on traffic
*/
constructor(relayAddr, rateLimit, pcConfig) {
constructor(relayAddr, rateLimit, config) {
this.prepareDataChannel = this.prepareDataChannel.bind(this);
this.connectRelay = this.connectRelay.bind(this);
this.onClientToRelayMessage = this.onClientToRelayMessage.bind(this);
......@@ -26,7 +26,8 @@ class ProxyPair {
this.relayAddr = relayAddr;
this.rateLimit = rateLimit;
this.pcConfig = pcConfig;
this.config = config;
this.pcConfig = config.pcConfig;
this.id = Util.genSnowflakeID();
this.c2rSchedule = [];
this.r2cSchedule = [];
......@@ -148,8 +149,19 @@ class ProxyPair {
// WebRTC --> websocket
onClientToRelayMessage(msg) {
if (this.messageTimer) {
clearTimeout(this.messageTimer);
}
dbg('WebRTC --> websocket data: ' + msg.data.byteLength + ' bytes');
this.c2rSchedule.push(msg.data);
// if we don't receive any keep-alive messages from the client, close the
// connection
this.messageTimer = setTimeout((() => {
console.log("Closing stale connection.");
this.flush()
this.close()
}), this.config.messageTimeout);
return this.flush();
}
......@@ -173,6 +185,10 @@ class ProxyPair {
clearTimeout(this.timer);
this.timer = 0;
}
if (this.messageTimer) {
clearTimeout(this.messageTimer);
this.messageTimer = 0;
}
if (this.webrtcIsReady()) {
this.client.close();
}
......@@ -244,6 +260,7 @@ ProxyPair.prototype.client = null; // WebRTC Data channel
ProxyPair.prototype.relay = null; // websocket
ProxyPair.prototype.timer = 0;
ProxyPair.prototype.messageTimer = 0;
ProxyPair.prototype.flush_timeout_id = null;
ProxyPair.prototype.onCleanup = null;
......@@ -134,7 +134,7 @@ class Snowflake {
return null;
}
var pair;
pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config.pcConfig);
pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config);
this.proxyPairs.push(pair);
log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
......
......@@ -43,7 +43,7 @@ describe('ProxyPair', function() {
destination = [];
// Using the mock PeerConnection definition from spec/snowflake.spec.js
var pp = new ProxyPair(fakeRelay, rateLimit, config.pcConfig);
var pp = new ProxyPair(fakeRelay, rateLimit, config);
beforeEach(function() {
return pp.begin();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment