> From: curl-library [[email protected]] on behalf of Joe Mason > [[email protected]] > > Aha, I think I see a timing assumption here: if request 2 starts to be > written, with CURLINFO_LASTSOCKET returning a value, in multi_perform before > multi_fdset is called, then sockets[N] will still be -1 and you'll get the > error "Handle 2 started on socket -1 and moved to N". Is that what you're > seeing?
If this seems to be the problem you're having, try the attached patch. Joe --------------------------------------------------------------------- This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.
From cee4eabdff5bc56813ea32fa211e2451623eb13e Mon Sep 17 00:00:00 2001 From: Joe Mason <[email protected]> Date: Fri, 24 Aug 2012 12:48:17 -0400 Subject: [PATCH] Deal with writing to a socket before it's detected --- tests/libtest/libntlmconnect.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-) diff --git a/tests/libtest/libntlmconnect.c b/tests/libtest/libntlmconnect.c index cabd26f..da7cec6 100644 --- a/tests/libtest/libntlmconnect.c +++ b/tests/libtest/libntlmconnect.c @@ -21,6 +21,7 @@ ***************************************************************************/ #include "test.h" +#include <assert.h> #include "testutil.h" #include "memdebug.h" @@ -44,10 +45,18 @@ static size_t callback(char* ptr, size_t size, size_t nmemb, void* data) return 0; } /* sock will only be set for NTLM requests; for others it is -1 */ - if (sock != -1 && sock != sockets[idx]) { - fprintf(stderr, "Handle %d started on socket %d and moved to %d\n", idx, sockets[idx], sock); - res = TEST_ERR_MAJOR_BAD; - return 0; + if (sock != -1) { + if (sockets[idx] == -1) { + /* Data was written for this request before the socket was detected by + multi_fdset. Record the socket now. */ + sockets[idx] = sock; + } + else if (sock != sockets[idx]) { + fprintf(stderr, "Handle %d started on socket %d and moved to %d\n", idx, + sockets[idx], sock); + res = TEST_ERR_MAJOR_BAD; + return 0; + } } return size * nmemb; } @@ -144,6 +153,9 @@ int test(char *url) if (!FD_ISSET(i, &fdread)) { continue; } + + /* Check if this socket was already detected for an earlier handle (or + for this handle, num_handles-1, in the callback */ for (j = 0; j < num_handles; ++j) { if (sockets[j] == i) { socket_exists = TRUE; @@ -160,9 +172,21 @@ int test(char *url) goto test_cleanup; } - sockets[num_handles-1] = i; - found_new_socket = TRUE; - /* continue to make sure there's only one new handle */ + /* Now we know the socket is for the most recent handle, num_handles-1 */ + if (sockets[num_handles-1] != -1) { + /* A socket for this handle was already detected in the callback; if it + matched socket_exists should be true and we would never get here */ + assert(i != sockets[num_handles-1]); + fprintf(stderr, "Handle %d wrote to socket %d then detected on %d\n", + num_handles-1, sockets[num_handles-1], i); + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } + else { + sockets[num_handles-1] = i; + found_new_socket = TRUE; + /* continue to make sure there's only one new handle */ + } } if (state == NeedSocketForNewHandle) { -- 1.7.5.4
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
