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

Close the session on error in client transports #623

Merged
merged 1 commit into from
May 9, 2023

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented May 8, 2023

By default, we close HTTP/2 connections after each request in Node.js.

But because of an oversight, the code handling the close never ran if we encountered an error, for example an unexpected response content type, or just an error encoded in the response body or response trailers of a streaming RPC.

@@ -78,6 +80,7 @@ export function createTransport(opt: CommonTransportOptions): Transport {
opt.jsonOptions,
opt
);
const ac = createLinkedAbortController(signal);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the relevant change: We create an AbortSignal and pass it to the HTTP client, and we wrap the rest of the Transport logic in a try-catch block and abort the signal on error. For HTTP/2, this closes the stream (and session), for HTTP/1.1 it calls destroy() on request and response.

!parsedType.stream &&
!parsedType.binary
) {
if (methodKind == MethodKind.Unary && parsedType && !parsedType.stream) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an unrelated fix. For Connect unary, we always try to parse an error from the response body if we receive a non-successful HTTP status - not just for JSON, but for protobuf binary as well. This has slipped through our test suite so far, but is covered now.

@timostamm timostamm merged commit 2f62c13 into main May 9, 2023
@timostamm timostamm deleted the tstamm/close-session-on-errors branch May 9, 2023 14:20
@timostamm timostamm mentioned this pull request May 17, 2023
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

Successfully merging this pull request may close these issues.

2 participants