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

Forwarding Connection header breaks after updating grpc/grpc-go to 1.42.0 #2447

Closed
MakDon opened this issue Dec 1, 2021 · 8 comments
Closed

Comments

@MakDon
Copy link
Contributor

MakDon commented Dec 1, 2021

🐛 Bug Report

grpc-gateway breaks after updating grpc/grpc-go to 1.42.0

After the update introduced by this PR, it will report stream terminated by RST_STREAM with error code: PROTOCOL_ERROR if connection in headers, which breaks down all of the http connections that comes with connect:keep-alive

To Reproduce

Step 1:
Update google.golang.org/grpc to v1.42.0 in go mod

Step 2:
invoke http request with header connect:keep-alive

Expected behavior

grpc-gateway works well or reports warning, instead of returning PROTOCOL_ERROR

Actual Behavior

it returns stream terminated by RST_STREAM with error code: PROTOCOL_ERROR

Your Environment

go.mod:
google.golang.org/grpc v1.42.0, github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0

@MakDon MakDon changed the title grpc-gateway breaks when grpc/grpc-go updated to 1.42.0 grpc-gateway breaks after updating grpc/grpc-go to 1.42.0 Dec 1, 2021
@johanbrandhorst
Copy link
Collaborator

Hm, this is curious, what should the behavior be here? Should the grpc-gateway strip these headers? I'm surprised we're forwarding this header, it should only forward explicitly added headers or permanent IANA headers (listed here:

func isPermanentHTTPHeader(hdr string) bool {
). Would you be willing to submit a test and a fix for this?

@MakDon
Copy link
Contributor Author

MakDon commented Dec 2, 2021

Hm, this is curious, what should the behavior be here? Should the grpc-gateway strip these headers? I'm surprised we're forwarding this header, it should only forward explicitly added headers or permanent IANA headers (listed here:

func isPermanentHTTPHeader(hdr string) bool {

). Would you be willing to submit a test and a fix for this?

ok, I'd like to submit a PR for it later.

@MakDon
Copy link
Contributor Author

MakDon commented Dec 2, 2021

Hm, this is curious, what should the behavior be here? Should the grpc-gateway strip these headers? I'm surprised we're forwarding this header, it should only forward explicitly added headers or permanent IANA headers (listed here:

func isPermanentHTTPHeader(hdr string) bool {

). Would you be willing to submit a test and a fix for this?

I found that my server breaks because i was using func(key string) (string, bool) {return key, true} header matcher for backward compatibility, which passthrough Connect header to grpc server and deserves a RST_STREAM

Connection header does not belong to permanent request headers maintained by IANA, so it seems not to be a good idea to add it into isPermanentHTTPHeader function body. And it would not breaks servers that uses DefaultHeaderMatcher cause it is not begins with Grpc-Metadata-

But for a further concern, is it a good idea that provides a backward-Compatible header matcher, which drops "malformed" headers for grpc and returns others headers as-is? It can be implemented like this:

func PassThroughHeaderMatcher(key string) (string, bool) {
	key = textproto.CanonicalMIMEHeaderKey(key)
	if isMalformedHTTPHeader(key) {
		return MetadataPrefix + key, true
	} else {
		return key, true
	}
}

Thanks very much.

@johanbrandhorst
Copy link
Collaborator

That is an interesting question. It would be nice to automatically help users who might suffer from this problem, but I'm also hesitant to do this implicitly. Maybe we could detect if the header matcher would match Connection on startup and log a warning?

@MakDon
Copy link
Contributor Author

MakDon commented Dec 3, 2021

That is an interesting question. It would be nice to automatically help users who might suffer from this problem, but I'm also hesitant to do this implicitly. Maybe we could detect if the header matcher would match Connection on startup and log a warning?

Agree. I tend to add a pre-matcher to match Connection and log a warning. Is it probable sulution?

@johanbrandhorst
Copy link
Collaborator

I think we can just try running any matcher with the Connection header when creating it in https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/mux.go#L115-L119 and log a warning if it matches. Would you be willing to contribute such a fix?

@johanbrandhorst johanbrandhorst changed the title grpc-gateway breaks after updating grpc/grpc-go to 1.42.0 Forwarding Connection header breaks after updating grpc/grpc-go to 1.42.0 Dec 4, 2021
@MakDon
Copy link
Contributor Author

MakDon commented Dec 4, 2021

Ok i am working on it.

@johanbrandhorst
Copy link
Collaborator

Fixed in #2455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants