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

Add graceful shutdown to HTTP server #178

Merged
merged 2 commits into from
Dec 14, 2022
Merged

Add graceful shutdown to HTTP server #178

merged 2 commits into from
Dec 14, 2022

Conversation

hhromic
Copy link
Contributor

@hhromic hhromic commented Dec 13, 2022

While troubleshooting #177, I noticed that graceful shutdown was missing for the HTTP server, making KMinion to hang on interrupt signals, e.g. Ctrl-c, instead of shutting down properly. For example:

# When using Ctrl-c _before_ the HTTP server is started, KMinion shutdowns cleanly
(...)
{"level":"info","ts":"2022-12-13T10:00:49.245Z","logger":"main","msg":"successfully connected to kafka cluster"}
<Ctrl-c>
{"level":"info","ts":"2022-12-13T10:00:49.940Z","logger":"main","msg":"received a signal, going to shut down KMinion"}
{"level":"fatal","ts":"2022-12-13T10:00:50.179Z","logger":"main","msg":"failed to start minion service","error":"failed to check feature compatibility against Kafka: kafka api versions couldn't be fetched: failed to request api versions: context canceled"}

# KMinion exits and returns control to the console
# When using Ctrl-c _after_ the HTTP server is started, KMinion never shutdowns and just hangs
(...)
{"level":"info","ts":"2022-12-13T10:01:13.735Z","logger":"main","msg":"listening on address","listen_address":":8080"}
<Ctrl-c>
{"level":"info","ts":"2022-12-13T10:01:14.410Z","logger":"main","msg":"received a signal, going to shut down KMinion"}

# KMinion never exits from this point and control never returns to the console

This PR fixes the above by properly implementing HTTP server shutdown when the context is cancelled.

Graceful shutdown was missing for the HTTP server, making kminion to hang on
interrupt signals, e.g. Ctrl-c, instead of shutting down properly.
@CLAassistant
Copy link

CLAassistant commented Dec 13, 2022

CLA assistant check
All committers have signed the CLA.

main.go Show resolved Hide resolved
Since Go 1.16, a signal-stoppable context can be created natively by the `signal` package.
@weeco weeco merged commit 5d28b6d into redpanda-data:master Dec 14, 2022
@hhromic hhromic deleted the http-graceful-shutdown branch December 14, 2022 15:17
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.

3 participants