Skip to content

Commit

Permalink
WiP Fix issue allegro#21: "node-worker don't run in windows"
Browse files Browse the repository at this point in the history
- in transport.send(), only call pipe.write once
- do not concat buffers when not on Windows (perf)

Payload of second call (containing `serializedMessage`) was getting lost, or at least not being received.

This appears to have _sort of_ fixed it...

I could not discern the exact root cause (something something pipes on windows).

Tests are still all passing on linux. Some failures on windows.
  • Loading branch information
dhharker committed Aug 28, 2018
1 parent eb32cff commit 7a1a8ab
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/worker/transport.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require("os");
const EventEmitter = require('events');
const msgpack = require("msgpack-lite");

Expand Down Expand Up @@ -52,11 +53,24 @@ class Transport extends EventEmitter {

send(message) {
const serializedMessage = msgpack.encode(message);
const header = new Uint32Array([ serializedMessage.byteLength ]);
const payloadLength = serializedMessage.byteLength;

this.pipe.write(Buffer.from(header.buffer));
this.pipe.write(serializedMessage);
const header = new Uint32Array([payloadLength]);

if (os.platform() === "win32") {
const headerLength = Uint32Array.BYTES_PER_ELEMENT * header.length;
this.pipe.write(
Buffer.concat(
[Buffer.from(header.buffer), serializedMessage],
payloadLength + headerLength
)
);
}
else {
this.pipe.write(Buffer.from(header.buffer));
this.pipe.write(serializedMessage);
}
}
}

module.exports = Transport;
module.exports = Transport;

0 comments on commit 7a1a8ab

Please sign in to comment.