-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support using process.on to listen SIGTERM #10
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||||||||
| /* eslint-disable @typescript-eslint/no-var-requires */ | ||||||||||||||||||||||||||||||||||
| const childProcess = require('node:child_process'); | ||||||||||||||||||||||||||||||||||
| const path = require('node:path'); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const childFile = path.join(__dirname, 'child.cjs'); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const child = childProcess.fork(childFile); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| process.once('SIGTERM', () => { | ||||||||||||||||||||||||||||||||||
| child.kill('SIGTERM'); | ||||||||||||||||||||||||||||||||||
| setTimeout(() => child.kill('SIGTERM'), 50); | ||||||||||||||||||||||||||||||||||
| setTimeout(() => process.exit(0), 1500); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using persistent SIGTERM listener when ALWAYS_ON_SIGTERM is set. Since this PR adds support for always listening to SIGTERM, this test fixture should demonstrate that behavior when the environment variable is set. -process.once('SIGTERM', () => {
+const sigtermHandler = () => {
child.kill('SIGTERM');
setTimeout(() => child.kill('SIGTERM'), 50);
setTimeout(() => process.exit(0), 1500);
-});
+};
+
+if (process.env.ALWAYS_ON_SIGTERM === 'Y') {
+ process.on('SIGTERM', sigtermHandler);
+} else {
+ process.once('SIGTERM', sigtermHandler);
+}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| console.log('master fork %s done', childFile); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider passing the ALWAYS_ON_SIGTERM environment variable to the child process.
Since the test in
index.test.tssets this environment variable and the cluster implementation uses it, this script should probably propagate it to ensure consistent behavior.