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

Listen for \q to gracefully shutdown the node #5389

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

kacpersaw
Copy link
Contributor

Motivation

Issue #5321

Listening for \q will allow smapp to gracefully shutdown the node.

@kacpersaw kacpersaw linked an issue Dec 22, 2023 that may be closed by this pull request
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (3675992) 0.0% compared to head (234a33b) 77.6%.
Report is 42 commits behind head on develop.

Files Patch % Lines
node/node.go 0.0% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #5389      +/-   ##
==========================================
+ Coverage         0   77.6%   +77.6%     
==========================================
  Files            0     266     +266     
  Lines            0   30906   +30906     
==========================================
+ Hits             0   24003   +24003     
- Misses           0    5389    +5389     
- Partials         0    1514    +1514     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brusherru
Copy link
Member

  • Works as expected on Windows.
  • And works the same on MacOS except for one thing not related to these changes.
  • I didn't check it on Linux, but I believe it should work as well :)

Inconsistent behavior when Node is compacting the database and receives \q:

  • On MacOS: it does not produce any log messages anymore (like "app cleanup starting..."), and just closes after a while. It works the same on previous versions of go-spacemesh using SIGTERM signal.
  • On Windows: it produces log messages and closes after a while

Except for this inconsistent behavior — LGTM.
So I'd be glad to have these changes if nobody is against the approach with stdin :)

@fasmat
Copy link
Member

fasmat commented Jan 11, 2024

I don't think listening to stdin is necessary to make a graceful shutdown on windows work. Instead we should try adding syscall.SIGINT to the argument list of signal.NotifyContext in node.go this should capture multiple signals on windows that are used to trigger an application to exit.

See also this change for it: https://go-review.googlesource.com/c/go/+/187739
it was added in Go 1.14. Relevant part in the release notes: https://go.dev/doc/go1.14#ossignalpkgossignal

EDIT: my bad - the problem is not the receiving program in windows its the sender. A assume GeneralConsoleCtrlEvent cannot be used? https://learn.microsoft.com/en-us/windows/console/generateconsolectrlevent?redirectedfrom=MSDN

node/node.go Outdated Show resolved Hide resolved
@fasmat fasmat marked this pull request as ready for review January 17, 2024 18:01
@fasmat
Copy link
Member

fasmat commented Jan 17, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Jan 17, 2024
## Motivation
Issue #5321

Listening for \q will allow smapp to gracefully shutdown the node.

Co-authored-by: Matthias <5011972+fasmat@users.noreply.github.com>
@spacemesh-bors
Copy link

Build failed:

@fasmat
Copy link
Member

fasmat commented Jan 18, 2024

The merge failed because reading from os.Stdin immediately returns io.EOF when the node runs inside docker - shutting down the app shortly after starting.

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.

Support WM_CLOSE for graceful shutdown on Windows
3 participants