-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some Domain APIs and Events never resolve/reject when connection to remote chrome instance fails. #304
Comments
It's not about some particular methods, every method is affected but since there is a race condition you may not always experience it. This problem is an instance of this, basically:
Based on your code this is a standalone example: const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
async function test() {
const chromeInstance = await chromeLauncher.launch({
chromeFlags: ['--headless', '--disable-gpu', '--no-sandbox']
});
const port = chromeInstance.port;
const client = await CDP({port});
chromeInstance.kill();
console.log('pre');
await client.DOM.enable();
console.log('post'); // never reached
}
test(); Now for what concerns the solution, you can register for the client.on('disconnect', () => {
console.log('disconnect');
}); |
Thanks (Y) @cyrus-and |
I'm confused why this isn't a valid bug. If node has had a chance to handle the websocket getting disconnected, then Promises that come back from the client will reject. But if Chrome dies and you call a method on the client before the event loop has had a chance to run, you end up with a Promise that never resolves. It seems like a bad idea to return a promise that has a small (but non-zero) chance of never resolving. |
@dinofx this is not a bug given the current implementation. But that's certainly a doable thing, at least for promises only, but to be coherent with the callbacks, they should fail upon disconnection too. And especially for events (that we should handle too), for example: await Page.loadEventFired(); But this would require a change in the API, because now they only accept the |
I totally agree with that. During our tests, if a network issue occurs, |
I was reading code and saw this part. As it should solve our issue but doesn't, I am investigating and trying to write a short test in order to find why we are facing this issue on our test stack. |
@cyrus-and Yes it does. Awesome ! Our dep version was stuck on 0.32.2. Many thanks, and by the way, I think this patch solved a lot of issues. Have a nice day. |
Is Chrome running in a container? NO
Chrome instance(Headless) is running on port 9222.
So the issue is that there are a few Domain APIs that never resolve or reject when connection to the remote chrome instance fails .
These are few Domain APIs that do reject with an error -
The above reject with an error . ("connect ECONNREFUSED 127.0.0.1:9222" , "read ECONNRESET" etc)
Where as The below just never resolve/reject and remain indefinitely in unresolved state.
Steps to reproduce the problem :
Note : The kill() should be asynchronous. If chrome is killed synchronously , CSS.enable() rejects with a "not opened" error message.
The real scenario :
Failure of connection establishment can happen in different ways -
The APIs must throw some kind of an error in this situation.
If not , everytime I use a new API , I should be careful to have a timeout .
The text was updated successfully, but these errors were encountered: