[tor-commits] [pluggable-transports/snowflake-webext] branch main updated: fix: stale connection not closing on timeout sometimes
gitolite role
git at cupani.torproject.org
Thu Nov 3 14:50:43 UTC 2022
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main
in repository pluggable-transports/snowflake-webext.
The following commit(s) were added to refs/heads/main by this push:
new 724281b fix: stale connection not closing on timeout sometimes
724281b is described below
commit 724281b06a122506f17a472ec20e5a34f02439ae
Author: WofWca <wofwca at protonmail.com>
AuthorDate: Thu Nov 3 13:05:17 2022 +0400
fix: stale connection not closing on timeout sometimes
When no messages from the client were ever sent
---
proxypair.js | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/proxypair.js b/proxypair.js
index dcd8433..481d0cd 100644
--- a/proxypair.js
+++ b/proxypair.js
@@ -79,10 +79,25 @@ class ProxyPair {
* @param {RTCDataChannel} channel
*/
prepareDataChannel(channel) {
+ // if we don't receive any keep-alive messages from the client, close the
+ // connection
+ const onStaleTimeout = () => {
+ console.log("Closing stale connection.");
+ this.flush();
+ this.close();
+ };
+ this.refreshStaleTimeout = () => {
+ clearTimeout(this.messageTimer);
+ this.messageTimer = setTimeout(onStaleTimeout, this.config.messageTimeout);
+ };
+
channel.onopen = () => {
log('WebRTC DataChannel opened!');
snowflake.ui.increaseClients();
this.counted = true;
+
+ this.refreshStaleTimeout();
+
// This is the point when the WebRTC datachannel is done, so the next step
// is to establish websocket to the server.
this.connectRelay();
@@ -154,17 +169,11 @@ class ProxyPair {
* @param {MessageEvent} msg
*/
onClientToRelayMessage(msg) {
- 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);
+ this.refreshStaleTimeout();
+
this.flush();
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tor-commits
mailing list