Make sure shutdown signals aren't trapped forever#313
Open
Tyler-Murphy wants to merge 1 commit intosignalwire:mainfrom
Open
Make sure shutdown signals aren't trapped forever#313Tyler-Murphy wants to merge 1 commit intosignalwire:mainfrom
Tyler-Murphy wants to merge 1 commit intosignalwire:mainfrom
Conversation
Right now, it seems like this library is preventing the `SIGINT` (ctrl-C) signal from shutting down my project. I made these changes using github's edit button, so I haven't tested/linted anything, and there could be mistakes. See this comment for an explanation: berstend/puppeteer-extra#467 (comment). Here are the comment's contents at the time of writing, in case the link stops working: I've run into problems like this before, where a `process.on` listener traps `SIGINT` every time it's sent. Reproduce the problem with this script. Run it and try hitting `ctrl-C` repeatedly. It'll be trapped every time and the process won't exit. ```node process.on(`SIGINT`, () => console.log(`caught SIGINT`)) setInterval(() => {}, 1e3) // do work to prevent immediate exit ``` I've fixed this a couple ways in the past. 1. Use `process.once`, and after cleanup work is complete, print a message saying something like "send SIGINT again to exit". 2. Re-emit the kill signal after cleanup work is complete. Option 2 seems like a better fit in this case, and it works better in conjunction with other, unrelated cleanup scripts with their own `SIGINT` listeners. Here's what it looks like: ```node process.once(`SIGINT`, () => { console.log(`caught SIGINT`) process.kill(process.pid, `SIGINT`) // send `SIGINT` back to self }) setInterval(() => {}, 1e3) // do work ``` I tried replacing [the `puppeteer-extra-plugin` `process.on` listeners in the `index` file](https://github.com/berstend/puppeteer-extra/blob/0049d6010311505f27e7f3be804bb198e2c09aa2/packages/puppeteer-extra-plugin/src/index.ts#L506-L519) with `process.once` listeners as described, and it seems to fix the problem for me. For example: ```node if (this.onClose) { if (opts.options.handleSIGINT !== false) { process.once('SIGINT', () => { this.onClose() process.kill(process.pid, `SIGINT`) }); } ... ``` **Note:** I haven't tested this against the other test cases in this thread, but it solved my problem. Maybe others can see if it works for them, too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Right now, it seems like this library is preventing the
SIGINT(ctrl-C) signal from shutting down my project.I made these changes using github's edit button, so I haven't tested/linted anything, and there could be mistakes. I have confirmed that making these changes causes
SIGINTto shut down my project like I expect it to.See this comment for an explanation: berstend/puppeteer-extra#467 (comment). Here are the comment's contents at the time of writing, in case the link stops working: