Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Fix cannot read property 'stdin' of null in some cases
Browse files Browse the repository at this point in the history
Add check for phantom._isDisposed before scheduling a new ping. This prevents a new ping from being scheduled
when a pong message is received after phantom.dispose() has been called.
  • Loading branch information
jhnns committed Oct 10, 2015
1 parent bcec7b6 commit 59e42e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ Phantom.prototype._schedulePing = function () {
// There is already a ping scheduled. It's unnecessary to schedule another one.
return;
}
if (this._isDisposed) {
// No need to schedule a ping, this instance is about to be disposed.
// Catches rare edge cases where a pong message is received right after the instance has been disposed.
// @see https://github.com/peerigon/phridge/issues/41
return;
}
this._pingTimeoutId = setTimeout(this._write, pingInterval, { action: "ping" });
};

Expand Down
11 changes: 11 additions & 0 deletions test/Phantom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ describe("Phantom", function () {
});
});

// @see https://github.com/peerigon/phridge/issues/41
it("should not schedule a new ping when a pong message is received right after calling dispose()", function () {
var message = JSON.stringify({ status: "pong" });
var promise = phantom.dispose();

// Simulate a pong message from PhantomJS
phantom._receive(message);

return promise;
});

});

});
Expand Down

0 comments on commit 59e42e4

Please sign in to comment.