Skip to content

Fix body read blocking on socket timeout instead of Content-Length#18

Open
Kruseltier wants to merge 1 commit intohaproxytech:masterfrom
Kruseltier:fix/receive-content-length-bytes
Open

Fix body read blocking on socket timeout instead of Content-Length#18
Kruseltier wants to merge 1 commit intohaproxytech:masterfrom
Kruseltier:fix/receive-content-length-bytes

Conversation

@Kruseltier
Copy link

socket:receive("*a") reads until the server closes the connection (EOF). When the server doesn't immediately close the connection (e.g. due to keep-alive or TCP linger behavior), this blocks until the socket timeout (default 5 seconds).

Fix by reading exactly Content-Length bytes with socket:receive(n), which returns as soon as the specified number of bytes have been received, regardless of connection state.

This matches the behavior already used in receive_chunked(), which correctly reads chunk_len+2 bytes rather than reading until EOF.

socket:receive("*a") reads until the server closes the connection (EOF).
When the server doesn't immediately close the connection (e.g. due to
keep-alive or TCP linger behavior), this blocks until the socket timeout
(default 5 seconds).

Fix by reading exactly Content-Length bytes with socket:receive(n), which
returns as soon as the specified number of bytes have been received,
regardless of connection state.

This matches the behavior already used in receive_chunked(), which
correctly reads chunk_len+2 bytes rather than reading until EOF.
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.

1 participant

Comments