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

fix(api-server): prevent race condition in server restart process #11731

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

o0charlie0o
Copy link
Contributor

Description

Fixes a race condition in the API server restart process where the newly started server could be killed by a lingering timeout handler from the previous shutdown sequence.

Changes

  • Refactored killApiServer to use a single promise with proper cleanup
  • Added cleanup function to remove exit listeners and clear timeouts
  • Ensured exit listeners are set up before sending kill signal to prevent missing exit events
  • Added proper logging for server shutdown states

Background

Previously, using Promise.race allowed both promises to continue executing even after one resolved, which could lead to the force-kill timeout executing after a new server had started. This fix ensures that only one shutdown path (graceful or force) can execute, and all listeners and timeouts are properly cleaned up.

Testing

To verify the fix:

  1. Start the dev server
  2. Make a change to trigger a server restart
  3. Confirm that the server successfully restarts and remains running
  4. Verify that multiple restarts work consistently

Fixes #11719

@Tobbe
Copy link
Member

Tobbe commented Nov 22, 2024

Thanks for the PR. I'll add it to my list of things to review

@Tobbe Tobbe self-assigned this Nov 22, 2024
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.

[Bug?]: Server is killed and doesn't come back up when saving changes
2 participants