-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(webserver): customize shutdown with new gracefulShutdown
option
#34130
Conversation
Co-authored-by: Dmitry Gozman <[email protected]> Signed-off-by: Simon Knott <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
docs/src/test-webserver-js.md
Outdated
@@ -37,6 +37,7 @@ export default defineConfig({ | |||
| `stdout` | If `"pipe"`, it will pipe the stdout of the command to the process stdout. If `"ignore"`, it will ignore the stdout of the command. Default to `"ignore"`. | | |||
| `stderr` | Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to `"pipe"`. | | |||
| `timeout` | How long to wait for the process to start up and be available in milliseconds. Defaults to 60000. | | |||
| `kill` | How to shut down the process gracefully. If unspecified, the process group is forcefully `SIGKILL`ed. If set to `{ SIGINT: 500 }`, the process group is sent a `SIGINT` signal, followed by `SIGKILL` if it doesn't exit within 500ms. You can also use `SIGTERM` instead. A `0` timeout means no `SIGKILL` will be sent. Windows doesn't support `SIGINT` and `SIGTERM` signals, so this option is ignored. | |
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.
I'd split it into 2 fields{ signal: SIGINT', timeout 5000 }
to make it clear that only one signal can be specified and what the value semantics is.
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.
Should we also rename it from kill
to shutdown
or gracefulShutdown
? At the moment, kill: undefined
means "KILL immediately", which could be surprising to some.
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.
refactored in 1361b4b
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.
Should we also rename it from
kill
toshutdown
orgracefulShutdown
?
I like gracefulShutdown
more. I'm sure there will be more opinions at the API review 😁
@@ -226,7 +226,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun | |||
killSet.delete(killProcessAndCleanup); | |||
removeProcessHandlersIfNeeded(); | |||
options.log(`[pid=${spawnedProcess.pid}] <kill>`); | |||
if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) { |
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.
Previously we wouldn't send the signal again if it has already been received, I believe it shouldn't matter for SIGKILL handling, but would be nice to double check.
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.
This change was needed for when we used launchedProcess.kill()
. We don't use that anymore, so i'll see if I can remove this change.
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.
yup, removed in 50305cc
This comment has been minimized.
This comment has been minimized.
attemptToGracefullyClose: () => Promise.reject(), | ||
attemptToGracefullyClose: async () => { | ||
if (process.platform === 'win32') | ||
throw new Error('Graceful shutdown is not supported on Windows'); |
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.
Windows users will now always see ...<gracefully close start>
followed by <will force kill>
in the logs. Not a big deal, but this was not the case before as we never announced graceful shutdown there. Maybe keep using kill
on Windows ?
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.
Don't think it makes any observable difference because log
is a no-op anyways (see L128). So it's purely a code complexity question. If we assigned _killProcess
depending on the platform, I worry that'd make us split execution more, and make this slightly harder to reason about I think. So i'll keep it as is for now.
kill
optiongracefulShutdown
option
Test results for "tests 1"4 flaky37513 passed, 653 skipped Merge workflow run. |
We had this change up earlier, but it staled because I was unsure what PID to signal. After doing some more research on it, it appears that both for
SIGINT
andSIGTERM
it's appropriate to send to the entire process group. So this PR is a reopening of #33379 with those learnings.Closes #33377, #18209