From d46b86c631b69facfc14e2e416e90fa54e0b38c8 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 18 Sep 2021 10:28:17 -0700 Subject: [PATCH] [#112] Fix race condition with closing sessions --- backend/api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/api.js b/backend/api.js index 433bc8d..da18dee 100644 --- a/backend/api.js +++ b/backend/api.js @@ -155,6 +155,11 @@ export class Session { logError(err); await this.teardown(); }); + // User may have closed websocket before we were able to set up + // the onclose listener. + if (this.ws.readyState === WebSocket.CLOSED) { + await this.teardown(); + } } catch (err) { logError(err); this.sendError(err);