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
14 changes: 8 additions & 6 deletions src/vs/base/parts/ipc/common/ipc.mp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export class Protocol implements IMessagePassingProtocol {
readonly onMessage;

constructor(private port: MessagePort) {
this.onMessage = Event.fromDOMEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => {
if (e.data) {
return VSBuffer.wrap(e.data);
}
return VSBuffer.alloc(0);
});
// A `message` event may carry no (or empty) data (e.g. during
// connection teardown). An empty frame is never a valid protocol
// message (the smallest valid frame still has a serialized header),
// so we must not forward it: doing so makes the channel readers
// deserialize an `undefined` header and crash. Filter these out at
// the transport boundary instead.
const onMessage = Event.fromDOMEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => e.data ? VSBuffer.wrap(e.data) : VSBuffer.alloc(0));
this.onMessage = Event.filter(onMessage, data => data.byteLength > 0);
// we must call start() to ensure messages are flowing
port.start();
}
Expand Down
Loading