From 57efedd0affd5e647db185aff0ba1be2a137aef3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 22 Jul 2023 07:11:48 -0400 Subject: [PATCH] fix: on write and end, log errors if we are trying to use a closed socket --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6769b6b..ef59788 100644 --- a/src/index.ts +++ b/src/index.ts @@ -229,15 +229,24 @@ export class Socket extends Client { } write(message: string | Buffer): void { + this.callModule("socketExists", { id: this.id }).then( + ([exists]: ErrTuple) => { + if (!exists) { + logErr("tried to write to closed socket"); + } + this.callModule("socketWrite", { id: this.id, message }); + }, + ); this.callModule("socketWrite", { id: this.id, message }); } end(): void { this.callModule("socketExists", { id: this.id }).then( ([exists]: ErrTuple) => { - if (exists) { - this.callModule("socketClose", { id: this.id }); + if (!exists) { + logErr("tried to close a closed socket"); } + this.callModule("socketClose", { id: this.id }); }, ); }