-
Notifications
You must be signed in to change notification settings - Fork 733
Closed
Description
Hello,
I'm testing a personal interceptor, and I realised that my test was crashing because the PingError
method of the TestServiceClient
panics in some conditions.
Here is the code I use to reproduce the issue:
package interceptor_test
import (
"net"
"testing"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/testing/testpb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func TestInterceptor(t *testing.T) {
lstConfig := net.ListenConfig{}
serverListener, err := lstConfig.Listen(t.Context(), "tcp", "")
if err != nil {
t.Fatalf("failed to listen: %v", err)
}
srv := grpc.NewServer()
testpb.RegisterTestServiceServer(srv, &testpb.TestPingService{})
go func() {
err := srv.Serve(serverListener)
if err != nil {
panic(err)
}
}()
grpcClientConn, err := grpc.NewClient(
serverListener.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
t.Fatalf("failed to connect: %v", err)
}
cli := testpb.NewTestServiceClient(grpcClientConn)
defer func() {
srv.Stop()
}()
_, err = cli.PingError(t.Context(), &testpb.PingErrorRequest{
Value: "hello",
})
if err != nil {
t.Fatal("calling Ping Err:", err.Error())
}
}
Here is the output of running this test:
▶ go test ./...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x8d6b35]
goroutine 22 [running]:
github.com/grpc-ecosystem/go-grpc-middleware/v2/testing/testpb.(*wrappedErrFields).Error(0xc0002146c0?)
/home/pascal/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware/[email protected]/testing/testpb/interceptor_suite.go:164 +0x15
google.golang.org/grpc/status.FromError({0xb3b2e0, 0xc0002146c0})
/home/pascal/go/pkg/mod/google.golang.org/[email protected]/status/status.go:108 +0xd3
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000184400, {0xb3f608, 0xc000214600}, 0xc00022e180, 0xc0001b26f0, 0xf4bed0, 0x0)
/home/pascal/go/pkg/mod/google.golang.org/[email protected]/server.go:1433 +0x13d5
google.golang.org/grpc.(*Server).handleStream(0xc000184400, {0xb3f8b8, 0xc000144000}, 0xc00022e180)
/home/pascal/go/pkg/mod/google.golang.org/[email protected]/server.go:1841 +0xb95
google.golang.org/grpc.(*Server).serveStreams.func2.1()
/home/pascal/go/pkg/mod/google.golang.org/[email protected]/server.go:1061 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 52
/home/pascal/go/pkg/mod/google.golang.org/[email protected]/server.go:1072 +0x11d
FAIL github.com/pascal/awesomeProject1 0.013s
FAIL
The bottomline is the call to New(codes.Unknown, err.Error())
in status.go
with a err == nil
variable.
func (err *wrappedErrFields) Error() string {
// Ideally we print wrapped fields as well
return err.wrappedErr.Error()
}
Here are the contents of my go.mod:
module github.com/pascal/awesomeProject1
go 1.25
require (
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2
google.golang.org/grpc v1.74.2
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
I don't know if this issue should be with the go-grpc-middleware
team, or if it should be with the golang.org/grpc
team.
Metadata
Metadata
Assignees
Labels
No labels