cURL
Haxx ad
libcurl

Shopping cart software, Online file storage, Online photo storage, Hosted shopping cart, Contact management software, Email marketing software, Project management software, Issue tracking software, Online notepad, Web publishing software

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

RE: Libcurl stops when sending lots of https messages

From: L S <zorkulus_at_hotmail.com>
Date: Fri, 6 Nov 2009 16:56:48 +0100

Hi again!

I believe I found the answer to why I had problems yesterday. Keep on reading for more information.

>Hi
>
>I'm writing a multi threaded application that sends https messages to a server.
>To keep it simple I use libcurl ( version curl-7.19.7 compiled with openSSL-0.9.8h) and the application runs on a Windows XP platform.

>Everything works just fine until i raise the number of messages sent per second. Then it sometimes stops in the middle of a send. The progress callback tells me that libcurl is finished sending the message to the server and waits for it's response which never occur. At this point one might blame the server for not responding the client correctly. But the server works just fine when using an old version of the application that doesn't use libcurl ( but still uses openSSL ).

>After investigating the problem with wireshark it seems that the server sends an "Encrypted handshake message" to the client after the client is done sending. When everything works out ok libcurl responds with another "Encrypted handshake message" >and the server starts sending a response.

I beleve that my problem is found in the Curl_ossl_recv function (found in ssluse.c) and I believe that it might be an error in how libcurl handle the SSL_ERROR_WANT_WRITE. Everytime I recieve that response code from SSL_get_error the comunication fails. According to "Network security with openssl", (O'reilly, page 158) the response code SSL_ERROR_WANT_WRITE means that we should retry the command that gave the response ( in this example SSL_read ). (Do libcurl use a blocking or nonblocking socket?) This is done correctly for return code SSL_ERROR_WANT_READ. The function Curl_ossl_recv is called again and with that SSL_read. But this never happends when SSL_ERROR_WANT_WRITE occur.

The reason for this is this code ( found in transfer.c ):

/* We go ahead and do a read if we have a readable socket or if
     the stream was rewound (in which case we have data in a
     buffer) */
  if((k->keepon & KEEP_RECV) &&
     ((select_res & CURL_CSELECT_IN) || conn->bits.stream_was_rewound)) {

    result = readwrite_data(data, conn, k, &didwhat, done);
    if(result || *done)
      return result;

The upper if statement isn't fulfilled after a SSL_ERROR_WANT_WRITE and thereby the readwrite_data function isn't called again. This results in a loop doing nothing until libcurl timeouts.

If this is considered to be an bug and not a feature ( there might be some reason for this that isn't libcurls fault. There are winsock calls involved that I don't know what they do ) then this little fix seems to work out for me.
In file Transfer.c line 449:

Change

/* subzero, this would've blocked */
      if(0 > readrc)
        break; /* get out of loop */

To

/* subzero, this would've blocked */
      if(0 > readrc)
      {
        conn->cselect_bits |= CURL_CSELECT_IN; //Remember that connection is of type CURL_CSELECT_IN
        break; /* get out of loop */

      }

I haven't this fix on a grander scheme. But for my application it seems to work.

If you want to reproduce the bug i suggest that you sent a couple of thousand https messages to a server running on a VMWare running on the same computer. I believe that SSL_ERROR_WANT_WRITE only occur from SSL_read when using a very fast connection.

If you have any better solutions please let me know

Hope that this is of any help to you. Just ask if you have any questions.

Best regards / Med vänliga hälsningar
Ludwig Sandström

                                               
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-11-06

These mail archives are generated by hypermail.

donate! Page updated November 16, 2009.
web site info

File upload with ASP.NET