Skip to content

Handle Nil response body from SigV4#749

Merged
jacksontj merged 1 commit intojacksontj:masterfrom
lewinkedrs:fix/nil-body-sigv4
Mar 18, 2026
Merged

Handle Nil response body from SigV4#749
jacksontj merged 1 commit intojacksontj:masterfrom
lewinkedrs:fix/nil-body-sigv4

Conversation

@lewinkedrs
Copy link
Copy Markdown
Contributor

Previously in #746 we added the capability for SigV4 support. This worked but did not handle the case where the response for a certain query was Nil. This caused a panic. In this change we handle the Nil case to prevent panic.

@lewinkedrs
Copy link
Copy Markdown
Contributor Author

Just to provide some context, here is the panic we got when would get a nil response body. I am also submitting this fix to prometheus/sigv4 to fix this in other places

goroutine 95 [running]:
bytes.(*Buffer).ReadFrom(0x14000a1e780, {0x0, 0x0})
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/bytes/buffer.go:211 +0x6c
io.copyBuffer({0x103a17a40, 0x14000a1e780}, {0x0, 0x0}, {0x0, 0x0, 0x0})
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/io/io.go:415 +0x14c
io.Copy(...)
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/io/io.go:388
github.com/prometheus/common/sigv4.(*sigV4RoundTripper).RoundTrip(0x140006dcc80, 0x14000888780)
        /Users/lewinke/promxy/vendor/github.com/prometheus/common/sigv4/sigv4.go:105 +0xcc
github.com/jacksontj/promxy/pkg/servergroup.(*ServerGroup).RoundTrip(0x14000484690, 0x14000888780)
        /Users/lewinke/promxy/pkg/servergroup/servergroup.go:114 +0x324
net/http.send(0x14000888780, {0x103a19bc0, 0x14000484690}, {0x10070e878?, 0x8?, 0x0?})
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/net/http/client.go:259 +0x498
net/http.(*Client).send(0x1400092e048, 0x14000888780, {0x1069d6fc0?, 0x100495ec0?, 0x0?})
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/net/http/client.go:180 +0x94
net/http.(*Client).do(0x1400092e048, 0x14000888780)
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/net/http/client.go:728 +0x764
net/http.(*Client).Do(...)
        /Users/lewinke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.6.darwin-arm64/src/net/http/client.go:587
github.com/prometheus/client_golang/api.(*httpClient).Do(0x1400092e040, {0x103a4f560, 0x140006e6460}, 0x14000888640?)
        /Users/lewinke/promxy/vendor/github.com/prometheus/client_golang/api/client.go:125 +0xf4
github.com/prometheus/client_golang/api/prometheus/v1.(*apiClientImpl).Do(0x103a4f4f0?, {0x103a4f560?, 0x140006e6460?}, 0x4?)
        /Users/lewinke/promxy/vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go:1365 +0x34
github.com/prometheus/client_golang/api/prometheus/v1.(*httpAPI).LabelValues(0x14000620710, {0x103a4f560, 0x140006e6460}, {0x14000a32012, 0x8}, {0x105767620, 0x0, 0x102779318?}, {0x14000923a38?, 0x14000a1e510?, ...}, ...)
        /Users/lewinke/promxy/vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go:1061 +0x430
github.com/jacksontj/promxy/pkg/promclient.(*PromAPIV1).LabelValues(0x14000620720, {0x103a4f560, 0x140006e6460}, {0x14000a32012, 0x8}, {0x105767620, 0x0, 0x0}, {0x14000923af8?, 0x5?, ...}, ...)
        /Users/lewinke/promxy/pkg/promclient/api.go:56 +0x124
github.com/jacksontj/promxy/pkg/promclient.(*AddLabelClient).LabelValues(0x140008ff008, {0x103a4f560, 0x140006e6460}, {0x14000a32012, 0x8}, {0x0?, 0x0?, 0x0?}, {0x0?, 0xffdf3b8149409a0a?, ...}, ...)
        /Users/lewinke/promxy/pkg/promclient/label.go:135 +0xbc

@lewinkedrs
Copy link
Copy Markdown
Contributor Author

Tests Passing:

❯ go test ./...
?       github.com/jacksontj/promxy     [no test files]
?       github.com/jacksontj/promxy/cmd/promxy  [no test files]
?       github.com/jacksontj/promxy/cmd/remote_write_exporter   [no test files]
ok      github.com/jacksontj/promxy/pkg/alertbackfill   (cached)
ok      github.com/jacksontj/promxy/pkg/config  (cached)
ok      github.com/jacksontj/promxy/pkg/logging (cached)
?       github.com/jacksontj/promxy/pkg/middleware      [no test files]
ok      github.com/jacksontj/promxy/pkg/promclient      (cached)
ok      github.com/jacksontj/promxy/pkg/promhttputil    (cached)
?       github.com/jacksontj/promxy/pkg/proxyquerier    [no test files]
ok      github.com/jacksontj/promxy/pkg/proxystorage    (cached)
ok      github.com/jacksontj/promxy/pkg/remote  (cached)
ok      github.com/jacksontj/promxy/pkg/server  (cached)
ok      github.com/jacksontj/promxy/pkg/servergroup     (cached)
ok      github.com/jacksontj/promxy/test        (cached)

@lewinkedrs
Copy link
Copy Markdown
Contributor Author

@pedroapero would you be able to take a look at this? Small change to handle an edge case from the SigV4 work.

@jacksontj jacksontj merged commit 7c64bd0 into jacksontj:master Mar 18, 2026
1 check passed
@lewinkedrs lewinkedrs deleted the fix/nil-body-sigv4 branch March 18, 2026 19:59
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