Skip to content

HTTP response could not be read if using POST on Windows #657

@Karlson2k

Description

@Karlson2k

This is actually a WinSock bug, but workaround can be implemented.
I discovered it while debugging GNU libmicrohttpd test suite.
Problem: WinSock destroy received data buffer if it detected TCP closure by remote side.

In practice:

  1. libcurl send HTTP request header
  2. HTTP server receive HTTP request header, replied with some HTTP error code and closed connection
  3. libcurl continue to send HTTP request (request body)
  4. WinSock on libcurl side detect rejection of data by remote side, set socket state to "closed by remote host"
  5. libcurl call recv(), but WinSock returns error WSAECONNABORTED or WSAECONNRESET. Received data is destroyed by WinSock. libcurl returns network error instead of real HTTP code.

To illustrate it, I've created small test suite:
https://github.com/Karlson2k/check_system_socket_recv_last

This bug is the reason why function testMultithreadedPostCancelPart in https://github.com/Karlson2k/libmicrohttpd/blob/master/src/testcurl/test_post.c#L538 failed when called with FLAG_SLOW_READ on Windows.

To workaround this Windows bug, libcurl must call recv() ASAP if incoming data is detected in CURLM_STATE_DOING, CURLM_STATE_DO_MORE states. Not sure that it can be easly implemented without breaking something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions