From ca88435617e59714a456031c75b3a329897d97bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Wed, 21 Jul 2021 20:07:06 -0500 Subject: [PATCH] fix: if websocket closed, don't produce a response --- lib/server/swarm.js | 1 + server.js | 2 +- test/request-handler.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/server/swarm.js b/lib/server/swarm.js index e1229c9..8194270 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -42,6 +42,7 @@ class Swarm { self._onAnnounceStarted(params, peer, id) } else if (params.event === 'stopped') { self._onAnnounceStopped(params, peer, id) + if (!cb) return // when websocket is closed } else if (params.event === 'completed') { self._onAnnounceCompleted(params, peer, id) } else if (params.event === 'update') { diff --git a/server.js b/server.js index a72b339..3bdbea7 100644 --- a/server.js +++ b/server.js @@ -588,7 +588,7 @@ class Server extends EventEmitter { event: 'stopped', numwant: 0, peer_id: socket.peerId - }, noop) + }) } }) } diff --git a/test/request-handler.js b/test/request-handler.js index 7e5e967..b60f967 100644 --- a/test/request-handler.js +++ b/test/request-handler.js @@ -14,10 +14,10 @@ function testRequestHandler (t, serverType) { class Swarm extends Server.Swarm { announce (params, cb) { super.announce(params, (err, response) => { - if (err) return cb(response) + if (cb && err) return cb(response) response.complete = 246 response.extraData = 'hi' - cb(null, response) + if (cb) cb(null, response) }) } }