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

main: handle termination signals #152

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

orbitalturtle
Copy link
Collaborator

@orbitalturtle orbitalturtle commented Aug 19, 2024

This PR fixes #150 with the following:

  • Uses tokio's signal feature to process SIGTERM and SIGINT signals, tying them to the triggered LifecycleSignals we had in place already.
  • Also uses the serve_with_shutdown tonic so the server shuts down more gracefully. Maybe it'd be worth looking to see if we can do more for a graceful shutdown later on. With this change, the server seems to work normally. But I'm realizing we don't have any quick integration tests of the server in place. This doesn't necessarily need to go in this PR... but if I have time I'll add something quick.

So that we can log some of the initial errors instead of printing them.
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 29 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (9c5727f) to head (f94892c).
Report is 5 commits behind head on master.

Files Patch % Lines
src/main.rs 0.00% 29 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master    #152   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           1       1           
  Lines         105     126   +21     
======================================
- Misses        105     126   +21     

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

Copy link
Contributor

@mrfelton mrfelton left a comment

Choose a reason for hiding this comment

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

tACK

@tnull
Copy link

tnull commented Aug 22, 2024

Want to note that since you already use tokio, you could also make use of its signal feature, which would allow to avoid the added dependency and might make signal handling even simpler (i.e., simply awaiting a signal stream that you could also use tokio::select on). See for example: https://github.com/tnull/ldk-node-offers-receive-test/blob/4c3f96713870c7127d81460384eca99420180e9f/src/main.rs#L59-L65 and https://github.com/tnull/ldk-node-offers-receive-test/blob/4c3f96713870c7127d81460384eca99420180e9f/src/main.rs#L122-L129

@orbitalturtle
Copy link
Collaborator Author

@tnull Good point, thank you!

@orbitalturtle orbitalturtle requested review from mrfelton and dunxen and removed request for mrfelton August 28, 2024 04:37
Comment on lines +67 to +83
let mut sigterm_stream = tokio::signal::unix::signal(SignalKind::terminate())
.map_err(|e| error!("Error initializing sigterm signal: {e}."))?;
let mut sigint_stream = tokio::signal::unix::signal(SignalKind::interrupt())
.map_err(|e| error!("Error initializing sigint signal: {e}."))?;

tokio::spawn(async move {
tokio::select! {
_ = sigint_stream.recv() => {
info!("Received CTRL-C, shutting down..");
shutdown.trigger();
}
_ = sigterm_stream.recv() => {
info!("Received SIGTERM, shutting down..");
shutdown.trigger();
}
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can add an issue to get integration tests for this up? I can look into it then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had actually already gotten pretty far into writing a basic integration test for this, before realizing it was probably too big for this PR heh. I'll either put it up as a draft or finish it off. But I have some further integration test ideas I'll post as issues today, if you happen to be interested.

@orbitalturtle orbitalturtle merged commit 210cfdf into lndk-org:master Aug 28, 2024
11 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.

Bug: lndk process does not respond to a SIGTERM
4 participants