Skip to content

fix: prevent nil pointer panic and close response body in RunPushGateway - #4

Open
azatmuhammetamanov01 wants to merge 1 commit into
labstack:mainfrom
azatmuhammetamanov01:fix-pushgateway-nil-response
Open

azatmuhammetamanov01 wants to merge 1 commit into
labstack:mainfrom
azatmuhammetamanov01:fix-pushgateway-nil-response

Conversation

@azatmuhammetamanov01

@azatmuhammetamanov01 azatmuhammetamanov01 commented Oct 7, 2026 •

Copy link
Copy Markdown

Problem

In RunPushGatewayGatherer, when client.Do(req) returns an error (e.g. the
push gateway is unreachable), the error handler is called but execution
continues to res.StatusCode. Since res is nil in that case, this causes a
nil pointer dereference panic.

Because the default ErrorHandler returns nil, any network error with the
default config crashes the application.

Additionally, res.Body was never closed, leaking connections.

Fix

  • continue after handling the client.Do error.
  • Close res.Body after a successful request.

Tests

Added TestRunPushGatewayGatherer_UnreachableGateway, which points the
gatherer at a closed server. Before the fix it panics with a nil pointer
dereference; after the fix it passes. go test -race ./... and go vet ./...
are clean.

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.

1 participant