Skip to content

Handle Request#Body == nil for outbound requests

I ran into a crash while working on Managed resources deletion (!2200 - merged):

plumbing_for_test.go:351: kas: panic: runtime error: invalid memory address or nil pointer dereference
plumbing_for_test.go:351: kas: [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc26a40]
plumbing_for_test.go:351: kas:
plumbing_for_test.go:351: kas: goroutine 240 [running]:
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*HTTPToOutboundGRPC).sendRequestBody(0xc002283b00, {0x2b12958, 0xc00377ad40}, {0x0, 0x0})
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/http_to_outbound_grpc.go:144 +0xe0
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*HTTPToOutboundGRPC).PipeInboundToOutbound(0xc002283b00, {0x2b12958, 0xc00377ad40}, 0xc000f952c0, {0x0, 0x0})
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/http_to_outbound_grpc.go:128 +0x530
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*HTTPRoundTripperToOutboundGRPC).RoundTrip(0xc002283b00, 0xc000f952c0)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/http_roundtripper_to_outbound_grpc.go:37 +0x1fc
plumbing_for_test.go:351: kas: net/http.send(0xc000f952c0, {0x2ae4540, 0xc002283b00}, {0x93dc8?, 0xc000119108?, 0x0?})
plumbing_for_test.go:351: kas: 	/usr/local/go/src/net/http/client.go:259 +0x6f0
plumbing_for_test.go:351: kas: net/http.(*Client).send(0xc002501410, 0xc000f952c0, {0x0?, 0x140?, 0x0?})
plumbing_for_test.go:351: kas: 	/usr/local/go/src/net/http/client.go:180 +0x104
plumbing_for_test.go:351: kas: net/http.(*Client).do(0xc002501410, 0xc000f952c0)
plumbing_for_test.go:351: kas: 	/usr/local/go/src/net/http/client.go:731 +0xdd0
plumbing_for_test.go:351: kas: net/http.(*Client).Do(...)
plumbing_for_test.go:351: kas: 	/usr/local/go/src/net/http/client.go:590
plumbing_for_test.go:351: kas: k8s.io/client-go/rest.(*Request).request(0xc000a44780, {0x2b04a98, 0xc003da7020}, 0xc00153c3b0)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/k8s.io/client-go@v0.32.1/rest/request.go:1228 +0x444
plumbing_for_test.go:351: kas: k8s.io/client-go/rest.(*Request).Do(0xc000a44780, {0x2b04a98, 0xc003da7020})
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/k8s.io/client-go@v0.32.1/rest/request.go:1275 +0x120
plumbing_for_test.go:351: kas: k8s.io/client-go/dynamic.(*dynamicResourceClient).Get(0xc002a8cd70, {0x2b04a98, 0xc003da7020}, {0xc0023b4a72, 0xe}, {{{0x0, 0x0}, {0x0, 0x0}}, {0x0, ...}}, ...)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/k8s.io/client-go@v0.32.1/dynamic/simple.go:247 +0x75c
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/managed_resources.(*ObjectManager).maybeDeleteObject(0xc002a6a740, {0x2b04a98, 0xc003da7020}, {{{0x0, 0x0}, {0xc0023b4a5e, 0x2}, {0xc0023b4a67, 0x9}}, {0x0, ...}, ...}, ...)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/managed_resources/object_manager.go:205 +0x2e4
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/managed_resources.(*ObjectManager).Delete(0xc002a6a740, {0x2b04a98, 0xc003da7020}, {0x7b, 0x141, {0xc0023b4a4a, 0x6}, {0xc00221c640, 0x2, 0x2}})
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/managed_resources/object_manager.go:160 +0x2f0
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/managed_resources/server.(*server).DeleteEnvironment(0xc001e15c20, {0x2b04a98, 0xc003da7020}, 0xc00200b380)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/managed_resources/server/server.go:169 +0x370
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/managed_resources/rpc._Provisioner_DeleteEnvironment_Handler.func1({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380})
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/managed_resources/rpc/rpc_grpc.pb.go:273 +0xc0
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/cmd/kas/kasapp.newAPIServer.UnaryServerErrorReporterInterceptor.func12({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380}, 0xc000e66e00, 0xc002c4e3a8)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/server_error_reporter.go:17 +0x68
plumbing_for_test.go:351: kas: google.golang.org/grpc.getChainUnaryHandler.func1({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380})
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1212 +0xd8
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/cmd/kas/kasapp.newAPIServer.UnaryServerValidatingInterceptor.func11({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380}, 0xc000e66e00?, 0xc002c42640)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/server_validator.go:21 +0xac
plumbing_for_test.go:351: kas: google.golang.org/grpc.getChainUnaryHandler.func1({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380})
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1212 +0xd8
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*JWTAuther).UnaryServerInterceptor(0xc0013065e8, {0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380}, 0x7d47e8?, 0xc002c42600)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/tool/grpctool/jwt_server_auth.go:61 +0x90
plumbing_for_test.go:351: kas: google.golang.org/grpc.getChainUnaryHandler.func1({0x2b04a98, 0xc003da7020}, {0x24f28c0, 0xc00200b380})
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1212 +0xd8
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/cmd/kas/kasapp.newAPIServer.UnaryRPCAPIInterceptor.func10({0x2b04a98, 0xc003da6b70}, {0x24f28c0, 0xc00200b380}, 0xc000e66e00, 0xc002c425c0)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/modshared/rpc_api.go:34 +0x84
plumbing_for_test.go:351: kas: google.golang.org/grpc.getChainUnaryHandler.func1({0x2b04a98, 0xc003da6b70}, {0x24f28c0, 0xc00200b380})
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1212 +0xd8
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/cmd/kas/kasapp.(*options).constructObservabilityTools.(*ServerMetrics).UnaryServerInterceptor.UnaryServerInterceptor.func3({0x2b04a98, 0xc003da6b70}, {0x24f28c0, 0xc00200b380}, 0xc000e66e00, 0xc002c42380)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware/v2@v2.2.0/interceptors/server.go:22 +0x218
plumbing_for_test.go:351: kas: google.golang.org/grpc.NewServer.chainUnaryServerInterceptors.chainUnaryInterceptors.func1({0x2b04a98, 0xc003da6b70}, {0x24f28c0, 0xc00200b380}, 0xc000e66e00, 0xc002c4e3a8)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1203 +0xb0
plumbing_for_test.go:351: kas: gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/module/managed_resources/rpc._Provisioner_DeleteEnvironment_Handler({0x24df920, 0xc001e15c20}, {0x2b04a98, 0xc003da6b70}, 0xc00243dd80, 0xc001f5c620)
plumbing_for_test.go:351: kas: 	/tmp/src/internal/module/managed_resources/rpc/rpc_grpc.pb.go:275 +0x1a4
plumbing_for_test.go:351: kas: google.golang.org/grpc.(*Server).processUnaryRPC(0xc001f52a00, {0x2b04a98, 0xc003da6690}, 0xc00200b200, 0xc001f685d0, 0x3ea4978, 0x0)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1400 +0x14d0
plumbing_for_test.go:351: kas: google.golang.org/grpc.(*Server).handleStream(0xc001f52a00, {0x2b05608, 0xc001af6d00}, 0xc00200b200)
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1810 +0xe64
plumbing_for_test.go:351: kas: google.golang.org/grpc.(*Server).serveStreams.func2.1()
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1030 +0xec
plumbing_for_test.go:351: kas: created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 159
plumbing_for_test.go:351: kas: 	/root/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1041 +0x1e8

Added a test and it fails without the fix:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1010de7d0]

goroutine 843 [running]:
testing.tRunner.func1.2({0x1015357c0, 0x101ea1bf0})
        GOROOT/src/testing/testing.go:1632 +0x2c4
testing.tRunner.func1()
        GOROOT/src/testing/testing.go:1635 +0x47c
panic({0x1015357c0?, 0x101ea1bf0?})
        GOROOT/src/runtime/panic.go:785 +0x124
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*HTTPToOutboundGRPC).sendRequestBody(0xc0004f2b40, {0x1016cf708, 0xc00098bbf0}, {0x0, 0x0})
        internal/tool/grpctool/http_to_outbound_grpc.go:148 +0xe0
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*HTTPToOutboundGRPC).PipeInboundToOutbound(0xc0004f2b40, {0x1016cf708, 0xc00098bbf0}, 0xc000816280, {0x0, 0x0})
        internal/tool/grpctool/http_to_outbound_grpc.go:128 +0x530
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*InboundHTTPToOutboundGRPC).pipeInboundToOutbound(0xc0004f2b40, {0x1016cf708, 0xc00098bbf0}, 0xc000057be0, {0x0, 0x0})
        internal/tool/grpctool/inbound_http_to_outbound_grpc.go:119 +0x184
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*InboundHTTPToOutboundGRPC).pipe(0xc0004f2b40, {0x1016c5ee8, 0xc00098bc08}, 0xc0009b9be0, {0x0, 0x0})
        internal/tool/grpctool/inbound_http_to_outbound_grpc.go:85 +0x208
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool.(*InboundHTTPToOutboundGRPC).Pipe(0xc0004f2b40, {0x1016c5ee8, 0xc00098bc08}, 0xc000057be0, {0x0, 0x0})
        internal/tool/grpctool/inbound_http_to_outbound_grpc.go:48 +0x54
gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v17/internal/tool/grpctool_test.TestHTTP2GRPC_HappyPath_GETNoBody(0xc00068a000)
        internal/tool/grpctool/inbound_http_to_outbound_grpc_test.go:183 +0x1588
testing.tRunner(0xc00068a000, 0x1016b2878)
        GOROOT/src/testing/testing.go:1690 +0x188
created by testing.(*T).Run in goroutine 1
        GOROOT/src/testing/testing.go:1743 +0x5e4

Merge request reports

Loading