socket error handling

This commit is contained in:
Ben Wilson
2023-08-14 10:19:01 -04:00
parent 31d4069e18
commit abbdf65925
+6 -1
View File
@@ -606,12 +606,17 @@ export class StratumV1Client {
} else { } else {
console.error(`Error: Cannot write to closed or ended socket. ${this.extraNonceAndSessionId} ${message}`); console.error(`Error: Cannot write to closed or ended socket. ${this.extraNonceAndSessionId} ${message}`);
this.destroy(); this.destroy();
if (!this.socket.destroyed) {
this.socket.destroy();
}
return false; return false;
} }
} catch (error) { } catch (error) {
this.destroy(); this.destroy();
if (!this.socket.destroyed && !this.socket.writableEnded) { if (!this.socket.writableEnded) {
await this.socket.end(); await this.socket.end();
} else if (!this.socket.destroyed) {
this.socket.destroy();
} }
console.error(`Error occurred while writing to socket: ${this.extraNonceAndSessionId}`, error); console.error(`Error occurred while writing to socket: ${this.extraNonceAndSessionId}`, error);
return false; return false;