Replace os.Exit in binoculars StartUp with error return#4782
Open
gnosyslambda wants to merge 1 commit intoarmadaproject:masterfrom
Open
Replace os.Exit in binoculars StartUp with error return#4782gnosyslambda wants to merge 1 commit intoarmadaproject:masterfrom
gnosyslambda wants to merge 1 commit intoarmadaproject:masterfrom
Conversation
Contributor
Greptile SummaryThis PR cleanly refactors Key changes and observations:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[main.go: main] --> B[ServeMetrics\ndefer shutdownMetricServer]
B --> C[serveHttp\ndefer shutdownGateway]
C --> D[binoculars.StartUp]
D --> E{Kubernetes\nClient?}
E -- error --> F[return nil, nil, error]
F --> G[log.Errorf]
G --> H[shutdownGateway explicit]
H --> I[shutdownMetricServer explicit]
I --> J[os.Exit 1]
E -- ok --> K{ConfigureAuth?}
K -- error --> F
K -- ok --> L[CreateGrpcServer\nSetup Services]
L --> M[wg := WaitGroup\nwg.Add 1\ngrpcCommon.Listen]
M --> N[return GracefulStop, wg, nil]
N --> O[Wait for stop signal\nshutdown]
O --> P[wg.Wait]
P --> Q[deferred shutdownGateway\ndeferred shutdownMetricServer]
Last reviewed commit: "refactor: replace os..." |
3b7794f to
2c7c7fb
Compare
c4f985c to
194f737
Compare
- StartUp now returns error instead of calling os.Exit(-1) - WaitGroup creation moved next to grpcCommon.Listen - Caller explicitly shuts down gateway and metrics before os.Exit(1) Fixes armadaproject#4779 Signed-off-by: gnosyslambda <gnosyslambda@gmail.com>
194f737 to
3f2bf70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4779
StartUp()ininternal/binoculars/server.gowas callingos.Exit(-1)on init errors, which makes the function impossible to test and prevents the caller from doing any cleanup.Changed the function to return an error instead, and updated the caller in
cmd/binoculars/main.goto handle it withlog.Fatalf. The end result is the same (process exits on failure), but now the logic is testable and the caller is in control.Changes:
StartUpsignature:(func(), *sync.WaitGroup)→(func(), *sync.WaitGroup, error)os.Exit(-1)calls replaced withfmt.Errorf+%wwrappingosandlogimports from server.go