Skip to content

Commit

Permalink
fix(Connection): do not assert that methods always have callbacks.
Browse files Browse the repository at this point in the history
In certain cases, all callbacks could be rejected before we get a
response from transport. This is easily reproducible with `slowMo`
option.

Fixes puppeteer#563.
  • Loading branch information
aslushnikov committed Apr 8, 2018
1 parent 8c54f41 commit 397b934
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ class Connection extends EventEmitter {
await new Promise(f => setTimeout(f, this._delay));
debugProtocol('◀ RECV ' + message);
const object = JSON.parse(message);
if (object.id && this._callbacks.has(object.id)) {
if (object.id) {
const callback = this._callbacks.get(object.id);
this._callbacks.delete(object.id);
if (object.error)
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): ${object.error.message} ${object.error.data}`));
else
callback.resolve(object.result);
// Callbacks could be all rejected if someone has called `.dispose()`.
if (callback) {
this._callbacks.delete(object.id);
if (object.error)
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): ${object.error.message} ${object.error.data}`));
else
callback.resolve(object.result);
}
} else {
console.assert(!object.id);
if (object.method === 'Target.receivedMessageFromTarget') {
const session = this._sessions.get(object.params.sessionId);
if (session)
Expand Down

0 comments on commit 397b934

Please sign in to comment.