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

SigV4 panics on GET requests / requests with nil body #562

Closed
tsipo opened this issue Jan 8, 2024 · 0 comments · Fixed by #673
Closed

SigV4 panics on GET requests / requests with nil body #562

tsipo opened this issue Jan 8, 2024 · 0 comments · Fixed by #673

Comments

@tsipo
Copy link

tsipo commented Jan 8, 2024

Hi there,

This issue was already reported here but the title of that issue is misleading. The problem is not with building the client, the problem is that (*sigV4RoundTripper).RoundTrip() assumes that the request has a non-nil body, as it tries to copy it using io.Copy(). That's what causes the panic.

I got this calling the API Buildinfo(), which is using a GET request (with nil body). For that matter, AMP doesn't expose the build info API at all (returns 404, as I could see using awscurl), but I don't even get there as the RoundTripper panics before the request is even sent.

Calling QueryRange() (or any other POST request) with the same config works perfectly fine.

This is what I get:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x56b134]

goroutine 1 [running]:
bytes.(*Buffer).ReadFrom(0xc000495b30, {0x0, 0x0})
/usr/local/go/src/bytes/buffer.go:211 +0x114
io.copyBuffer({0x155e2e0, 0xc000495b30}, {0x0, 0x0}, {0x0, 0x0, 0x0})
/usr/local/go/src/io/io.go:416 +0x25a
io.Copy({0x155e2e0, 0xc000495b30}, {0x0, 0x0})
/usr/local/go/src/io/io.go:389 +0x79
github.com/prometheus/common/sigv4.(*sigV4RoundTripper).RoundTrip(0xc0000bf860, 0xc000472500)
/home/roy/go/pkg/mod/github.com/prometheus/common/[email protected]/sigv4.go:105 +0x19b
...
github.com/prometheus/client_golang/api.(*httpClient).Do(0xc0004c6140, {0x1564e00, 0xc0000bf7c0}, 0xc000472500)
/home/roy/go/pkg/mod/github.com/prometheus/[email protected]/api/client.go:125 +0xe9
github.com/prometheus/client_golang/api/prometheus/v1.(*apiClientImpl).Do(0xc0004c0530, {0x1564e00, 0xc0000bf7c0}, 0xc000472400)
/home/roy/go/pkg/mod/github.com/prometheus/[email protected]/api/prometheus/v1/api.go:1382 +0xd4
github.com/prometheus/client_golang/api/prometheus/v1.(*httpAPI).Buildinfo(0xc0004c0540, {0x1564e00, 0xc0000bf7c0})
/home/roy/go/pkg/mod/github.com/prometheus/[email protected]/api/prometheus/v1/api.go:999 +0x203
...

roidelapluie added a commit to roidelapluie/common that referenced this issue Aug 9, 2024
Fixes prometheus#562
Fixes prometheus#465

Signed-off-by: Julien Pivotto <[email protected]>
@SuperQ SuperQ closed this as completed in 1dade5b Aug 11, 2024
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 a pull request may close this issue.

1 participant