Skip to content
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

Merged
merged 32 commits into from
Jan 3, 2025

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Dec 22, 2024

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 and SIGTERM it's appropriate to send to the entire process group. So this PR is a reopening of #33379 with those learnings.

Closes #33377, #18209

@Skn0tt Skn0tt requested a review from dgozman December 22, 2024 10:52
@Skn0tt Skn0tt self-assigned this Dec 22, 2024

This comment has been minimized.

This comment has been minimized.

@@ -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. |
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored in 1361b4b

Copy link
Member

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?

I like gracefulShutdown more. I'm sure there will be more opinions at the API review 😁

packages/playwright/src/plugins/webServerPlugin.ts Outdated Show resolved Hide resolved
@@ -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) {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@Skn0tt Skn0tt requested a review from yury-s January 2, 2025 16:49
attemptToGracefullyClose: () => Promise.reject(),
attemptToGracefullyClose: async () => {
if (process.platform === 'win32')
throw new Error('Graceful shutdown is not supported on Windows');
Copy link
Member

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 ?

Copy link
Member Author

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.

@Skn0tt Skn0tt changed the title feat(webserver): customize shutdown with new kill option feat(webserver): customize shutdown with new gracefulShutdown option Jan 3, 2025
Copy link
Contributor

github-actions bot commented Jan 3, 2025

Test results for "tests 1"

4 flaky ⚠️ [firefox-page] › page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/proxy.spec.ts:63:3 › should work with IP:PORT notion @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:39:3 › should upload a folder @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

37513 passed, 653 skipped
✔️✔️✔️

Merge workflow run.

@Skn0tt Skn0tt merged commit 6bdd269 into microsoft:main Jan 3, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Graceful shutdown of webservers
2 participants