Skip to content

Conversation

@mrfelton
Copy link
Contributor

@mrfelton mrfelton commented Jul 8, 2019

This is an attempt to get a fix for #941

There are 2 things here:

  1. Correctly check http error status codes as number rather than string. This is probably correct.

  2. Trigger handleTrailers in the case of an http error. This is probably not the right thing to do, but I'm not very familiar with the codebase or protocol and I'm literally just hacking away trying to get the result I'm looking for. This does fix the error I'm experiencing, although probably not the right way to go about it.

}

if (flags & http2.constants.NGHTTP2_FLAG_END_STREAM) {
if (flags & http2.constants.NGHTTP2_FLAG_END_STREAM || this.mappedStatusCode !== Status.OK) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if the END_STREAM flag is not set, then there will still be actual trailers later. I think there might be a better solution here that doesn't involve discarding those trailers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured. I'm open to suggestions!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplest solution for now would probably be to just remove that end event handler I linked to in the issue. I think that check actually doesn't exist in the other implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work because the status code set in mappedStatusCode only gets handled in handleTrailers, which never gets called again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something worth noting here is that in the case that I'm working with, the problem arrises when grpc is is being served behind nginx with grpc_pass.

In this case, nginx serves the 404 error - so I don't think the trailers ever come.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some further debugging it seems that the nginx proxy was incorrectly setup in my case. So, I have updated this PR to remove the changes related to the handing of the trailers - it now just fixes the http status code checking (number vs string)

} else {
this.http2Stream = stream;
stream.on('response', (headers, flags) => {
switch (headers[HTTP2_HEADER_STATUS]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line now has to say headers[':status'] so that TypeScript can recognize that the value will be a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@murgatroid99 murgatroid99 merged commit c186e6d into grpc:master Jul 8, 2019
@murgatroid99
Copy link
Member

Thank you for your contribution

@murgatroid99
Copy link
Member

0.5.1 is now out with this fix.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants