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

Feature/graceful shutdown #291

Merged
merged 3 commits into from
Feb 4, 2023
Merged

Feature/graceful shutdown #291

merged 3 commits into from
Feb 4, 2023

Conversation

kiwiidb
Copy link
Contributor

@kiwiidb kiwiidb commented Jan 17, 2023

Fixes #285
Based on this article.

We need to shutdown a maximum of 3 servers:

  • The main Echo REST server
  • (optional) The Prometheus metrics server
  • (optional) The gRPC server
    These servers are shut down gracefully by calling some kind of Stop or Shutdown function from main.go after backgroundCtx is canceled, which is done when the signal receives an os.Interupt (Ctrl-c) signal.

Other than that there are the background routines:

  • Incoming invoice gRPC subscription routine
  • Payment tracking routines
  • Webhook dispatching routines

These are also canceled by canceling the backgroundCtx context. The waitgroup waits until all processes are finished before the program is exited.

@kiwiidb kiwiidb requested a review from bumi January 17, 2023 10:33
@@ -243,11 +243,6 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error {
if err != nil {
svc.Logger.Errorf("Error processing invoice update subscription: %v", err)
sentry.CaptureException(err)
// TODO: close the stream somehoe before retrying?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to remove this because the "error" that is returned here, if there is one, is most likely the context cancellation. Even if it is some kind of other error, I feel it doesn't really make sense to add these kind of ad-hoc reconnects here.

@kiwiidb kiwiidb merged commit 7a01bf6 into main Feb 4, 2023
@kiwiidb kiwiidb deleted the feature/graceful-shutdown branch February 4, 2023 10:31
This pull request was closed.
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.

Graceful shutdown of all goroutines
2 participants