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

Set "Connection: close" for non-keep-alive requests #7087

Merged
merged 1 commit into from Mar 20, 2024

Conversation

scotttrinh
Copy link
Contributor

See a similar boolean check in the _handle_response method:

if response.close_connection or not request.should_keep_alive:
self.close()

This fixes an issue where we were not setting the Connection: close header unless you specifically set response.close_connection, but some HTTP Request implementations (in this case node.Request via Remix's fetch implementation) were treating that as a socket hang up error (meaning it didn't send the end event before closing the socket).

According to the HTTP 1.1 Spec:

> An HTTP/1.1 server MAY assume that a HTTP/1.1 client intends to
> maintain a persistent connection unless a Connection header including
> the connection-token "close" was sent in the request. If the server
> chooses to close the connection immediately after sending the
> response, it SHOULD send a Connection header including the
> connection-token close.
https://www.rfc-editor.org/rfc/rfc2616#section-8.1.2.1

The Node.js `Request` module depends on getting the header `Connection:
close` to properly sequence socket messages, otherwise it throws a
"socket hang up" error.

This issue was found due to Remix having a custom implementation of
`fetch` that use's Node.js's `Request` module, which has different
behavior than the native Node.js `fetch` global.
@scotttrinh scotttrinh force-pushed the set-response-connection-close branch from 36e1524 to 43952a6 Compare March 20, 2024 19:29
@scotttrinh scotttrinh merged commit 8f1de04 into master Mar 20, 2024
23 checks passed
@scotttrinh scotttrinh deleted the set-response-connection-close branch March 20, 2024 19:55
vpetrovykh pushed a commit that referenced this pull request Mar 27, 2024
According to the HTTP 1.1 Spec:

> An HTTP/1.1 server MAY assume that a HTTP/1.1 client intends to
> maintain a persistent connection unless a Connection header including
> the connection-token "close" was sent in the request. If the server
> chooses to close the connection immediately after sending the
> response, it SHOULD send a Connection header including the
> connection-token close.
https://www.rfc-editor.org/rfc/rfc2616#section-8.1.2.1

The Node.js `Request` module depends on getting the header `Connection:
close` to properly sequence socket messages, otherwise it throws a
"socket hang up" error.

This issue was found due to Remix having a custom implementation of
`fetch` that use's Node.js's `Request` module, which has different
behavior than the native Node.js `fetch` global.
vpetrovykh pushed a commit that referenced this pull request Mar 27, 2024
According to the HTTP 1.1 Spec:

> An HTTP/1.1 server MAY assume that a HTTP/1.1 client intends to
> maintain a persistent connection unless a Connection header including
> the connection-token "close" was sent in the request. If the server
> chooses to close the connection immediately after sending the
> response, it SHOULD send a Connection header including the
> connection-token close.
https://www.rfc-editor.org/rfc/rfc2616#section-8.1.2.1

The Node.js `Request` module depends on getting the header `Connection:
close` to properly sequence socket messages, otherwise it throws a
"socket hang up" error.

This issue was found due to Remix having a custom implementation of
`fetch` that use's Node.js's `Request` module, which has different
behavior than the native Node.js `fetch` global.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants