Repository navigation
fix(echoprometheus): don't panic when push gateway is unreachable - #152
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
When client.Do failed and the ErrorHandler returned nil (the default), RunPushGatewayGatherer fell through to res.StatusCode with a nil response and panicked. Skip to the next tick instead, and drain and close the response body so connections are reused. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
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.
RunPushGatewayGathererpanics with a nil pointer dereference whenever the push gateway can't be reached (connection refused, DNS failure, timeout) and theErrorHandlerreturns nil, which is what the defaultErrorHandlerdoes:So with the default config, a push gateway that goes down for a moment crashes the application's push goroutine (and the process). The response body was also never closed, which leaks a connection on every push.
Changes:
continueto the next tick after aclient.Doerror has been passed to theErrorHandler.TestRunPushGatewayGatherer_unreachableGatewayDoesNotPanic: it points at a closed httptest server with anErrorHandlerthat returns nil. On master it panics atprometheus.go:448. With the fix it returnscontext.DeadlineExceeded, and the handler sees "error sending to push gateway".Tests:
go test ./echoprometheus/,go test -race ./echoprometheus/,go vet,gofmtandstaticcheck -tests=false ./echoprometheus/are clean.The same code was copied into labstack/echo-prometheus, where labstack/echo-prometheus#4 proposes the same fix.
This change was prepared with AI assistance and reviewed by me.