socket error handling

This commit is contained in:
Ben Wilson 2023-08-14 10:19:01 -04:00
parent 31d4069e18
commit abbdf65925

View File

@ -606,12 +606,17 @@ export class StratumV1Client {
} else {
console.error(`Error: Cannot write to closed or ended socket. ${this.extraNonceAndSessionId} ${message}`);
this.destroy();
if (!this.socket.destroyed) {
this.socket.destroy();
}
return false;
}
} catch (error) {
this.destroy();
if (!this.socket.destroyed && !this.socket.writableEnded) {
if (!this.socket.writableEnded) {
await this.socket.end();
} else if (!this.socket.destroyed) {
this.socket.destroy();
}
console.error(`Error occurred while writing to socket: ${this.extraNonceAndSessionId}`, error);
return false;