common icon indicating copy to clipboard operation
common copied to clipboard

SigV4 panics on GET requests / requests with nil body

Open tsipo opened this issue 2 years ago • 0 comments

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 ...

tsipo avatar Jan 08 '24 23:01 tsipo