{"action":"closed","issue":{"url":"https://api.github.com/repos/curl/curl/issues/657","repository_url":"https://api.github.com/repos/curl/curl","labels_url":"https://api.github.com/repos/curl/curl/issues/657/labels{/name}","comments_url":"https://api.github.com/repos/curl/curl/issues/657/comments","events_url":"https://api.github.com/repos/curl/curl/issues/657/events","html_url":"https://github.com/curl/curl/issues/657","id":133799139,"number":657,"title":"HTTP response could not be read if using POST on Windows","user":{"login":"Karlson2k","id":1898693,"avatar_url":"https://avatars.githubusercontent.com/u/1898693?v=3","gravatar_id":"","url":"https://api.github.com/users/Karlson2k","html_url":"https://github.com/Karlson2k","followers_url":"https://api.github.com/users/Karlson2k/followers","following_url":"https://api.github.com/users/Karlson2k/following{/other_user}","gists_url":"https://api.github.com/users/Karlson2k/gists{/gist_id}","starred_url":"https://api.github.com/users/Karlson2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karlson2k/subscriptions","organizations_url":"https://api.github.com/users/Karlson2k/orgs","repos_url":"https://api.github.com/users/Karlson2k/repos","events_url":"https://api.github.com/users/Karlson2k/events{/privacy}","received_events_url":"https://api.github.com/users/Karlson2k/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-15T19:38:01Z","updated_at":"2016-04-20T08:06:28Z","closed_at":"2016-04-20T08:06:28Z","body":"This is actually a WinSock bug, but workaround can be implemented.\r\nI discovered it while debugging [GNU libmicrohttpd](https://github.com/karlson2k/libmicrohttpd) test suite.\r\nProblem: WinSock destroy received data buffer if it detected TCP closure by remote side.\r\n\r\nIn practice:\r\n\r\n1. libcurl send HTTP request header\r\n2. HTTP server receive HTTP request header, replied with some HTTP error code and closed connection\r\n3. libcurl continue to send HTTP request (request body)\r\n4. WinSock on libcurl side detect rejection of data by remote side, set socket state to \"closed by remote host\"\r\n5. 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.\r\n\r\nTo illustrate it, I've created small test suite:\r\nhttps://github.com/Karlson2k/check_system_socket_recv_last\r\n\r\nThis 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.\r\n\r\nTo 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."}}