Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions barretenberg/ts/src/bb_backends/node/native_socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ export class BarretenbergNativeSocketAsyncBackend implements IMsgpackBackendAsyn
connectionReject = null;
connectionResolve = null;
}
// Reject all pending callbacks
// Reject all pending callbacks and destroy socket to prevent further writes
const error = new Error(`Native backend process error: ${err.message}`);
for (const callback of this.pendingCallbacks) {
callback.reject(error);
}
this.pendingCallbacks = [];
if (this.socket) {
this.socket.destroy();
this.socket = null;
}
});

this.process.on('exit', (code, signal) => {
Expand All @@ -113,12 +117,16 @@ export class BarretenbergNativeSocketAsyncBackend implements IMsgpackBackendAsyn
connectionReject = null;
connectionResolve = null;
}
// Reject all pending callbacks
// Reject all pending callbacks and destroy socket to prevent further writes
const error = new Error(errorMsg);
for (const callback of this.pendingCallbacks) {
callback.reject(error);
}
this.pendingCallbacks = [];
if (this.socket) {
this.socket.destroy();
this.socket = null;
}
});

// Wait for bb to create socket file, then connect
Expand Down Expand Up @@ -306,6 +314,7 @@ export class BarretenbergNativeSocketAsyncBackend implements IMsgpackBackendAsyn
// Unref so socket doesn't keep event loop alive
// this.socket.unref();
this.socket.destroy();
this.socket = null;
}
} catch (e) {
// Ignore errors during cleanup
Expand Down
Loading