-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
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:
- libcurl send HTTP request header
- HTTP server receive HTTP request header, replied with some HTTP error code and closed connection
- libcurl continue to send HTTP request (request body)
- WinSock on libcurl side detect rejection of data by remote side, set socket state to "closed by remote host"
- libcurl call recv(), but WinSock returns error
WSAECONNABORTEDorWSAECONNRESET. 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.