Skip to content

Commit

Permalink
fix(driver): stop sending protocol messages after disconnect (#4688)
Browse files Browse the repository at this point in the history
When the client only closes the input pipe, we are still
sending protocol messages over the output pipe. This could
probably lead to some errors, e.g. write buffer being full.
  • Loading branch information
dgozman committed Dec 16, 2020
1 parent 94f5002 commit 7385b31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/driver.ts
Expand Up @@ -50,15 +50,17 @@ export function runServer() {

const dispatcherConnection = new DispatcherConnection();
const transport = new Transport(process.stdout, process.stdin);
transport.onmessage = message => dispatcherConnection.dispatch(JSON.parse(message));
dispatcherConnection.onmessage = message => transport.send(JSON.stringify(message));
transport.onclose = async () => {
// Drop any messages during shutdown on the floor.
dispatcherConnection.onmessage = () => {};
// Force exit after 30 seconds.
setTimeout(() => process.exit(0), 30000);
// Meanwhile, try to gracefully close all browsers.
await gracefullyCloseAll();
process.exit(0);
};
transport.onmessage = message => dispatcherConnection.dispatch(JSON.parse(message));
dispatcherConnection.onmessage = message => transport.send(JSON.stringify(message));

const playwright = new Playwright(__dirname, require('../browsers.json')['browsers']);
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/transport.ts
Expand Up @@ -47,7 +47,11 @@ export class Transport {
this._endian = endian;
this._closeableStream = closeable;
pipeRead.on('data', buffer => this._dispatch(buffer));
pipeRead.on('close', () => this.onclose && this.onclose());
pipeRead.on('close', () => {
this._closed = true;
if (this.onclose)
this.onclose();
});
this.onmessage = undefined;
this.onclose = undefined;
}
Expand Down

0 comments on commit 7385b31

Please sign in to comment.