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

Merged
merged 5 commits into from
Dec 9, 2024

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

Tobbe commented Dec 8, 2024

I'm back reviewing PRs! Adding a reminder for this one for next week.

@Tobbe Tobbe added the release:fix This PR is a fix label Dec 9, 2024
@Tobbe Tobbe added this to the next-release-patch milestone Dec 9, 2024
@Tobbe Tobbe merged commit 6ee583f into redwoodjs:main Dec 9, 2024
50 checks passed
@lintfail
Copy link

Could we please have a patch release with this fix? Thanks in advance @Tobbe

Copy link
Member

Tobbe commented Dec 21, 2024

I'm planning on getting a release out this weekend

@lintfail
Copy link

Thank you so much! @Tobbe

Copy link
Member

Tobbe commented Dec 23, 2024

Unfortunately didn't get it out today. Will keep working on it tomorrow

@lintfail
Copy link

@Tobbe Appreciate it, thank you so much!

Tobbe added a commit that referenced this pull request Dec 25, 2024
@Tobbe Tobbe modified the milestones: next-release-patch, v8.4.2 Dec 25, 2024
Copy link
Member

Tobbe commented Dec 25, 2024

Finally! 😄 https://github.com/redwoodjs/redwood/releases/tag/v8.4.2 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
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
4 participants