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

Client panic when server sends 0 connect.ErrorCode #396

Closed
joshcarp opened this issue Nov 17, 2022 · 0 comments · Fixed by #398
Closed

Client panic when server sends 0 connect.ErrorCode #396

joshcarp opened this issue Nov 17, 2022 · 0 comments · Fixed by #398
Labels
bug Something isn't working

Comments

@joshcarp
Copy link
Contributor

Describe the bug

The client panics when server sends 0 connect.ErrorCode

To Reproduce

func TestZeroCode(t *testing.T) {
	mux := http.NewServeMux()
	pluggableServer := &pluggablePingServer{
		ping: func(_ context.Context, _ *connect.Request[pingv1.PingRequest]) (*connect.Response[pingv1.PingResponse], error) {
			return nil, connect.NewError(0, errors.New("error"))
		},
	}
	mux.Handle(pingv1connect.NewPingServiceHandler(pluggableServer))
	server := httptest.NewServer(mux)
	t.Cleanup(server.Close)
	connectClient := pingv1connect.NewPingServiceClient(server.Client(), server.URL)
	connectResp, err := connectClient.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{}))
	assert.NotNil(t, err)
	assert.Nil(t, connectResp)
}

Yields:

=== RUN   TestZeroCode
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10043fcb0]

goroutine 7 [running]:
github.com/bufbuild/connect-go.(*connectUnaryClientConn).validateResponse(0x140001e8100, 0x14000222090)
	/Users/joshcarp/Documents/github.com/bufbuild/connect-go/protocol_connect.go:423 +0x900
github.com/bufbuild/connect-go.(*duplexHTTPCall).makeRequest(0x140001ce880)
	/Users/joshcarp/Documents/github.com/bufbuild/connect-go/duplex_http_call.go:257 +0xac
created by github.com/bufbuild/connect-go.(*duplexHTTPCall).ensureRequestMade.func1
	/Users/joshcarp/Documents/github.com/bufbuild/connect-go/duplex_http_call.go:233 +0x64


Process finished with the exit code 1

Environment (please complete the following information):

  • connect-go v1.1.0
@joshcarp joshcarp added the bug Something isn't working label Nov 17, 2022
joshcarp referenced this issue Nov 18, 2022
- Maps a zero code of `connectWireError` to a CodeUnknown in
`connectWireError) asError() *Error `
This could have been done in the unmarshaling to `connectWireError` but
I chose to leave that to be exactly what was read off the wire.
- Adds nil guard in `validateResponse` for asError
- Adds tests for error mapping

Fixes: https://github.com/bufbuild/connect-go/issues/396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant