http: response dropped when client half-closes after sending request (request still executed) #36454

issue ViniciusCestarii opened this issue on October 7, 2026
  1. ViniciusCestarii commented at 7:00 PM on October 7, 2026: contributor

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    With the new HTTP server (#35182), if a client sends a complete request and then half-closes its write side (shutdown(SHUT_WR), i.e. sends FIN), the server closes the connection without writing a response. The request is still executed.

    Some tools (nc -N, socat) rely on it. Was the change intentional?

    This was found while testing v32.0rc

    Expected behaviour

    The server should write the response and then close, as v31 (libevent) did.

    Steps to reproduce

    bitcoind -regtest -daemon
    python3 -c '
      import socket, sys
      s = socket.create_connection(("127.0.0.1", 18443))
      s.sendall(b"GET / HTTP/1.1\r\nHost: x\r\n\r\n")
      s.shutdown(socket.SHUT_WR)
      while (d := s.recv(4096)): sys.stdout.buffer.write(d)
    '
    

    This on v32rc gives no output.

    On v31 it does:

    Bitcoin Core starting
    HTTP/1.1 405 Method Not Allowed
    Date: Wed, 07 Oct 2026 18:57:26 GMT
    Content-Length: 41
    Content-Type: text/html; charset=ISO-8859-1
    
    JSONRPC server handles only POST requests⏎ 
    

    Relevant log output

    No response

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    9dfde64cc3262329051fd05fffe40eecc786a99f

    Operating system and version

    Arch Linux, kernel 7.1.8-arch1-3

    Machine specifications

    No response

  2. pinheadmz commented at 7:02 PM on October 7, 2026: member

    Thanks, would this be solved by #35780 ?

  3. ViniciusCestarii commented at 7:18 PM on October 7, 2026: contributor

    that was a fast reply :). Tried #35780, but it doesn't solve this

  4. tumutech commented at 11:16 PM on October 7, 2026: none

    I followed the reproduce steps and on v32.0rc there was no output , on v31 i got the following output

    HTTP/1.1 405 Method Not Allowed
    Date: Wed, 07 Oct 2026 21:24:35 GMT
    Content-Length: 41
    Content-Type: text/html; charset=ISO-8859-1
    
    JSONRPC server handles only POST requests
    

    I tried adding a check in HTTPRemoteClient::MaybeDisconnect that checks if the client is marked for disconnect while a request is still running or a reply is still queued and then keeps the connection until a reply is sent.

    if (m_disconnect && (m_req_busy || ReadyToSend())) return false;

    Here is the link to the commit i made http: send reply before disconnect on client half-close

    Is this approach acceptable? I have tested it out and it returned the response below instead of a blank output after running this test. Test run:

    bitcoind -regtest -daemon

    python3 -c '
    import socket, sys
    s = socket.create_connection(("127.0.0.1", 18443))
    s.sendall(b"GET / HTTP/1.1\r\nHost: x\r\n\r\n")
    s.shutdown(socket.SHUT_WR)
    while (d := s.recv(4096)): sys.stdout.buffer.write(d)
    '
    

    Output: Bitcoin Core starting

    HTTP/1.1 405 Method Not Allowed
    Date: Wed, 07 Oct 2026 23:06:48 GMT
    Content-Length: 41
    Content-Type: text/html; charset=ISO-8859-1
    
    JSONRPC server handles only POST requests
    

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-10-14 18:51 UTC

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