-
Notifications
You must be signed in to change notification settings - Fork 53
Fix: Prevent server process from hanging during stop operation #1067
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
Conversation
fredrikekelund
left a comment
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.
Does what it says on the tin 👍
I'll create a separate issue for investigating why the Remote Data Blocks plugin throws an error like this, but this is still a great improvement.
src/lib/site-server-process.ts
Outdated
| if ( process && process.pid ) { | ||
| require( 'process' ).kill( process.pid, 'SIGKILL' ); | ||
| } else { | ||
| if ( ! isResolved ) { | ||
| isResolved = true; | ||
| resolve(); | ||
| } | ||
| } |
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.
| if ( process && process.pid ) { | |
| require( 'process' ).kill( process.pid, 'SIGKILL' ); | |
| } else { | |
| if ( ! isResolved ) { | |
| isResolved = true; | |
| resolve(); | |
| } | |
| } | |
| if ( process.pid ) { | |
| kill( process.pid, 'SIGKILL' ); | |
| } else { | |
| isResolved = true; | |
| resolve(); | |
| } |
Nit, but we already know that process is defined at this point, and we also know that isResolved is false because this callback returns early if that's the case.
I also don't see a good reason to use the require pattern here – we might as well do import { kill } from 'process';
src/lib/site-server-process.ts
Outdated
| } | ||
| resolve(); | ||
| } ); | ||
| process.kill(); |
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.
process.kil() returns a boolean per the Electron docs. Is that a useful signal for us maybe..?
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.
That's a nice catch!
I've made some adjustments to use the return value from process.kill() instead of the TIMEOUT.
Could you take another look, please? 🙏
wojtekn
left a comment
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.
Looks good @bcotrim .
Could you please update description to account for the timeout removal?
fredrikekelund
left a comment
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.
Nice 👍 New solution also works as expected.
src/lib/site-server-process.ts
Outdated
| } ); | ||
| process.kill(); | ||
| // process.kill() returns false if we're not able to kill the process. | ||
| if ( ! process.kill() && ! isResolved ) { |
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.
| if ( ! process.kill() && ! isResolved ) { | |
| if ( ! process.kill() ) { |
I can't really imagine a scenario in which isResolved would be true at this point 🤔
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 guess I was being extra careful with that condition, but it doesn't make sense anymore with the new approach.
I have removed isResolved check and works as expected.
Thanks for the feedback!
src/lib/site-server-process.ts
Outdated
| reject( new Error( `Site server process exited with code ${ code } upon stopping` ) ); | ||
| return; | ||
| if ( ! isResolved ) { | ||
| isResolved = true; |
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.
| isResolved = true; |
Nit, but given that we're only listening to the exit event once, do we really need to modify isResolved here?
* prevent the server from hanging on stop * adjust forcekill process * adjust forcekill process * remove isResolved check
Related issues
Proposed Changes
Testing Instructions
Follow the steps mentioned in the issue
More details on reproducing the issue (thanks @ppolo99): p1741865890679379/1741864717.468099-slack-C04GESRBWKW
Pre-merge Checklist