check isClosed
before issuing retries for a failed job
#325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes prevent
puppeteer-cluster
from thinking that the browser has closed withProtocol error (Runtime.callFunctionOn): Target closed.
orNavigation failed because browser has disconnected!
and issuing retries whencluster.close()
is called. Since this method should only be used aftercluster.idle()
I think this is much more reasonable behavior (at least it fits my use case below!).The added test case demonstrates this well. Before the change the new test case fails in this manor:
After the change, all tests pass!
The use case for this is aborting long running scrape jobs. My particular issue is that my cloud environment may kill an HTTP request and issue its own retries (kicking off duplicate scrapes), and my long running scrape job needs to abort. With an
http.IncomingRequest
from node.js this is pretty straightforwardUnfortunately, what I was finding was that
puppeteer-cluster
wasn't aborting like I wanted it to! Instead it was detecting a browser crash and restarting.The current implementation leaves the
taskerror
event being called (withjobWillRetry
now set to false) even after isClosed has resolved and returned true. I don't have a preference for if this is right or not (aftercluster.close()
I could argue that no events should be emitted), but worth calling out as to being how the implementation currently works