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

Panic with query parameters #324

Closed
fische opened this issue Mar 13, 2017 · 1 comment
Closed

Panic with query parameters #324

fische opened this issue Mar 13, 2017 · 1 comment

Comments

@fische
Copy link
Contributor

fische commented Mar 13, 2017

Hi!
It appears that the runtime panics when you try to set a subfield of a non-object field in the query parameters.

For example, we will take the following protobuf:

syntax = "proto3";

package pb;

import "google/api/annotations.proto";

service Service {
	rpc Method (Message) returns (Message) {
		option (google.api.http) = {
			get: "/method"
		};
	}
}

message Message {
	string msg = 1;
}

With this protobuf, the runtime will panic, if you try to set a subfield (let's say sth) of msg in the query parameters, like this:

curl http://$HOST:$PORT/method?msg.sth=test

Here is the stacktrace from the panic:

2017/03/13 14:35:47 http: panic serving [::1]:49154: proto: type must have kind struct
goroutine 50 [running]:
net/http.(*conn).serve.func1(0xc4201f0000)
	/usr/lib/go/src/net/http/server.go:1491 +0x12a
panic(0x79cb80, 0xc4201fe320)
	/usr/lib/go/src/runtime/panic.go:458 +0x243
github.com/golang/protobuf/proto.GetProperties(0xa0c760, 0x79cb80, 0x198)
	/home/fische_m/Project/Go/src/github.com/golang/protobuf/proto/properties.go:643 +0x17a
github.com/grpc-ecosystem/grpc-gateway/runtime.fieldByProtoName(0x79cb80, 0xc4201fe2c0, 0x198, 0xc4201ec0d0, 0x3, 0x79cb80, 0xc4201fe2c0, 0x198, 0xc42021a000)
	/home/fische_m/Project/Go/src/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:93 +0x5e
github.com/grpc-ecosystem/grpc-gateway/runtime.populateFieldValueFromPath(0xa06460, 0xc4201fe2c0, 0xc4201fc2c0, 0x2, 0x2, 0xc4201fe2e0, 0x1, 0x1, 0xc4201ec0cc, 0x7)
	/home/fische_m/Project/Go/src/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:51 +0x12e
github.com/grpc-ecosystem/grpc-gateway/runtime.PopulateQueryParameters(0xa06460, 0xc4201fe2c0, 0xc4201ec2d0, 0xa29780, 0x79cb80, 0xc4201fe1c0)
	/home/fische_m/Project/Go/src/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go:24 +0x1c3
_/home/fische_m/local/test/gateway/pb.request_Service_Method_0(0x7ff3ca2b9028, 0xc4201ec2a0, 0xa08580, 0xa1e0c0, 0xa00a20, 0xc42003c050, 0xc420208000, 0xc4201ec1e0, 0x0, 0xc4201ec1e0, ...)
	/home/fische_m/local/test/gateway/pb/example.pb.gw.go:38 +0xd8
_/home/fische_m/local/test/gateway/pb.RegisterServiceHandler.func1(0xa07160, 0xc420210000, 0xc420208000, 0xc4201ec1e0)
	/home/fische_m/local/test/gateway/pb/example.pb.gw.go:94 +0x228
github.com/grpc-ecosystem/grpc-gateway/runtime.(*ServeMux).ServeHTTP(0xc420017e60, 0xa07160, 0xc420210000, 0xc420208000)
	/home/fische_m/Project/Go/src/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go:89 +0x7f9
net/http.serverHandler.ServeHTTP(0xc420026300, 0xa07160, 0xc420210000, 0xc420208000)
	/usr/lib/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc4201f0000, 0xa079a0, 0xc4201e8140)
	/usr/lib/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
	/usr/lib/go/src/net/http/server.go:2293 +0x44d
@tmc
Copy link
Collaborator

tmc commented Mar 13, 2017

@fische thanks for the issue report. This scenario should be handled more gracefullly. Perhaps a codes.InvalidArgument/http.StatusBadRequest with a helpful message would be best.

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

No branches or pull requests

2 participants