http: linger-close after parse errors so clients can read the reply #35740

pull b-l-u-e wants to merge 1 commits into bitcoin:master from b-l-u-e:http-lingering-close changing 7 files +164 −35
  1. b-l-u-e commented at 4:21 AM on July 17, 2026: contributor

    On Windows the malformed HTTP requests intermittently lose their error response. The server queues the reply and closes the connection right away and sometimes before it has finished reading everything the client sent. Windows reacts to that by resetting the TCP connection and the reset carries the queued response away with it so as the client never sees the 400

    as we saw this in check_whitespace_in_headers instead of the expected HTTP 400 the client will occasionally get a bare ConnectionAbortedError.

    so decided to change how the server closes connections after a parse error so as it gives the client a chance to read the response before it hangs up:

    1. Queue the 400 or 413 response with Connection: close.
    2. Wait for the response to actually leave the send buffer.
    3. Half-close the socket's write side with shutdown(SD_SEND/SHUT_WR) so the client can still finish reading while we stop sending.
    4. Keep draining whatever the client sends until it hits EOF or a permanent socket error.
    5. Only force-close after one secondand only as a fallback for a client that never finishes.

    also added Sock::ShutdownSend() to wrap the platform-specific half-close call and made sure the linger state is consistent whether it's touched from the I/O thread or from a worker's send path.

  2. http: linger-close after parse errors so clients can read the reply
    Avoid RST on Windows when closing with unread request bytes (#35632).
    6729f17247
  3. DrahtBot added the label RPC/REST/ZMQ on Jul 17, 2026
  4. DrahtBot commented at 4:21 AM on July 17, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35740.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where comparison-specific test macros should replace generic comparisons:

    • [test/functional/interface_http.py] assert iterations >= 1 -> assert_greater_than_or_equal(iterations, 1)

    <sup>2026-07-17 04:21:37</sup>

  5. b-l-u-e closed this on Jul 17, 2026

  6. b-l-u-e deleted the branch on Jul 17, 2026
  7. b-l-u-e restored the branch on Jul 17, 2026
  8. b-l-u-e deleted the branch on Jul 19, 2026
  9. b-l-u-e restored the branch on Jul 22, 2026
Contributors

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-25 06:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me