Skip to content

Commit 7069fbc

Browse files
fix: check if the socket exists in the worker
Reference: https://nodejs.org/api/child_process.html#child_process_example_sending_a_socket_object > Any 'message' handlers in the subprocess should verify that socket exists, as the connection may have been closed during the time it takes to send the connection to the child. Without this check, the following exception could be thrown: internal/per_context/primordials.js:23 return (thisArg, ...args) => ReflectApply(func, thisArg, args); ^ TypeError: Cannot convert undefined or null to object at hasOwnProperty (<anonymous>) at internal/per_context/primordials.js:23:32 at getOrSetAsyncId (internal/async_hooks.js:396:7) at Server.connectionListener (_http_server.js:414:5) at Server.emit (events.js:315:20) Related: #1
1 parent ad38b06 commit 7069fbc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ const setupWorker = (io) => {
9999
process.on("message", ({ type, data }, socket) => {
100100
switch (type) {
101101
case "sticky:connection":
102+
if (!socket) {
103+
// might happen if the socket is closed during the transfer to the worker
104+
// see https://nodejs.org/api/child_process.html#child_process_example_sending_a_socket_object
105+
return;
106+
}
102107
io.httpServer.emit("connection", socket); // inject connection
103108
// republish first chunk
104109
if (socket._handle.onread.length === 1) {

0 commit comments

Comments
 (0)