mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 14:11:50 +03:00
fix(driver): stop sending protocol messages after disconnect (#4688)
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.
This commit is contained in:
parent
94f5002ae4
commit
7385b31f13
@ -50,15 +50,17 @@ export function runServer() {
|
|||||||
|
|
||||||
const dispatcherConnection = new DispatcherConnection();
|
const dispatcherConnection = new DispatcherConnection();
|
||||||
const transport = new Transport(process.stdout, process.stdin);
|
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 () => {
|
transport.onclose = async () => {
|
||||||
|
// Drop any messages during shutdown on the floor.
|
||||||
|
dispatcherConnection.onmessage = () => {};
|
||||||
// Force exit after 30 seconds.
|
// Force exit after 30 seconds.
|
||||||
setTimeout(() => process.exit(0), 30000);
|
setTimeout(() => process.exit(0), 30000);
|
||||||
// Meanwhile, try to gracefully close all browsers.
|
// Meanwhile, try to gracefully close all browsers.
|
||||||
await gracefullyCloseAll();
|
await gracefullyCloseAll();
|
||||||
process.exit(0);
|
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']);
|
const playwright = new Playwright(__dirname, require('../browsers.json')['browsers']);
|
||||||
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
|
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
|
||||||
|
@ -47,7 +47,11 @@ export class Transport {
|
|||||||
this._endian = endian;
|
this._endian = endian;
|
||||||
this._closeableStream = closeable;
|
this._closeableStream = closeable;
|
||||||
pipeRead.on('data', buffer => this._dispatch(buffer));
|
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.onmessage = undefined;
|
||||||
this.onclose = undefined;
|
this.onclose = undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user