From 4f21ab970db03f4596b3bd001539059ac6248fe8 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 3 Aug 2022 22:22:40 -0400 Subject: [PATCH] *Check if socket exists before closing to prevent errors on possible race conditions --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0b4d3e3..7c0ea18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -150,7 +150,11 @@ export class Socket extends EventEmitter { } end(): void { - callModule(DHT_MODULE, "close", { id: this.id }); + callModule(DHT_MODULE, "socketExists", { id: this.id }).then(([exists]: ErrTuple) => { + if (exists) { + callModule(DHT_MODULE, "close", { id: this.id }); + } + }); } private ensureEvent(event: string): void {