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

Do not attempt to send a response to a closed connection/stream #141

Merged
merged 3 commits into from
Apr 12, 2016

Conversation

trustin
Copy link
Member

@trustin trustin commented Apr 11, 2016

Motivation:

An HTTP/2 stream can be closed by various reasons, such as RST_STREAM
and GOAWAY frame. If Armeria server attempts to write a response to a
closed connection or a closed HTTP/2 stream, Netty's Http2Connection
will reject it with an unexpected exception, such as:

Http2Exception: Cannot create stream 1 since this endpoint has
                received a GOAWAY frame with last stream id 0

Http2Exception: Request stream N is not correct for server
                connection

Http2Exception: Request stream ODD_N is not correct for server
                connection

Modifications:

  • Make sure that the connection is still active and the HTTP/2 stream
    associated with the response is still not closed
  • Replace useHeadOfBlocking flag with http2conn field which becomes
    non-null when upgraded to HTTP/2
  • Miscellaneous:
    • Remove redundant Future.isDone() check
    • Set the 'content-length' even if the current protocol is HTTP/1 and
      the response being written is the last response, to work around
      overly strict clients

Result:

Less mysterious yet noisy exceptions in the log

@trustin trustin added the defect label Apr 11, 2016
@trustin trustin added this to the 0.13.4.Final milestone Apr 11, 2016
return;
}

if (!handledLastRequest) {
addKeepAliveHeaders(res);
ctx.write(res).addListener(CLOSE_ON_FAILURE);
} else {
// Note that it is perfectly fine not to set the 'content-length' header to the last response
// of an HTTP/1 connection. We just set it to work around overly strict HTTP servers that always
Copy link
Collaborator

Choose a reason for hiding this comment

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

HTTP clients

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

Motivation:

An HTTP/2 stream can be closed by various reasons, such as RST_STREAM
and GOAWAY frame. If Armeria server attempts to write a response to a
closed connection or a closed HTTP/2 stream, Netty's Http2Connection
will reject it with an unexpected exception, such as:

    Http2Exception: Cannot create stream 1 since this endpoint has
                    received a GOAWAY frame with last stream id 0

    Http2Exception: Request stream N is not correct for server
                    connection

    Http2Exception: Request stream ODD_N is not correct for server
                    connection

Modifications:

- Make sure that the connection is still active and the HTTP/2 stream
  associated with the response is still not closed
- Replace useHeadOfBlocking flag with http2conn field which becomes
  non-null when upgraded to HTTP/2
- Miscellaneous:
  - Remove redundant Future.isDone() check
  - Set the 'content-length' even if the current protocol is HTTP/1 and
    the response being written is the last response, to work around
    overly strict clients

Result:

Less mysterious yet noisy exceptions in the log
@blmarket
Copy link
Contributor

it also solves #140, LGTM!

Heon Jeong and others added 2 commits April 12, 2016 12:38
…Java identifier part

Motivation:

The default logger name of the service bound at '/200' becomes:

    armeria.services._00

which could have been:

    armeria.services._200
@anuraaga
Copy link
Collaborator

LGTM

@trustin trustin merged commit b48f38a into line:master Apr 12, 2016
@trustin trustin deleted the check_before_responding branch April 12, 2016 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants