cURL / Mailing Lists / curl-library / Single Mail

curl-library

Win32 Libcurl 7.16.0 - Concurrent Perform calls lock application

From: Manuel Reyes <Manuel.Reyes_at_e-mis.com>
Date: Tue, 20 Feb 2007 10:47:52 -0000

Hello list,

In order to send HTTP posts, as per the title of this post, I am
currently using a Win32 build of Libcurl 7.16.0.

I am currently working in .NET 1.1 (service pack 1) and use C# as the
primary language, I am also using the Libcurl.NET from here:

http://sourceforge.net/projects/libcurl-net/

After running a series of tests I found an intermittent error. In
summary my application receives requests to push HTTP post data to a
series of different endpoints using client/server certification. As
this app is a server application sometimes multiple requests can be
submitted at the same time. Each request that the application receives
is processed on its own thread and therefore is does not queue requests.

What I have found is that, when processing multiple requests through
libcurl, sometimes the application locks when the Perform is called. At
this point no further requests can be passed into the application and it
needs to be restarted to bring everything back together.

After running through some tests most concurrent requests will fail,
from reviewing the logs there seems to be a small window where something
in Libcurl ceases to function correctly (thread safety???)

Whilst the code I am using uses the Libcurl.NET wrapper and technically
this isn't the correct forum for it, I don't believe the issue is with
the library as the Libcurl.NET Perform method wraps directly onto the
Libcurl.dll. So this is the code:

////////////////////////////////////////////////////////////////////
//Global init/cleanup is called when the app starts/closes not here

DotNetCurl.Easy easy = new DotNetCurl.Easy();

//set response writer method
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_WRITEFUNCTION, new
DotNetCurl.Easy.WriteFunction(OnCurlWriteData));

//set the SSL context manager
//OnCurlSSLContext doesn't currently do anything and simply
//returns curl OK.
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_SSL_CTX_FUNCTION, new
DotNetCurl.Easy.SSLContextFunction(OnCurlSSLContext));

//set headers
DotNetCurl.Slist sl = new DotNetCurl.Slist();
sl.Append(Helpers.FormatProviders.StringFormat("POST {0} HTTP/1.1",
uri.PathAndQuery));
sl.Append(Helpers.FormatProviders.StringFormat("SOAPAction: {0}",
soapAction));
sl.Append(Helpers.FormatProviders.StringFormat("Content-Type: {0}",
contentType));
sl.Append(Helpers.FormatProviders.StringFormat("Content-Length: {0}",
sendData.Length));
sl.Append(Helpers.FormatProviders.StringFormat("Host: {0}:{1}",
uri.Host, uri.Port));
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_HTTPHEADER, sl);

//set other message params
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_URL, uri.AbsoluteUri);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_POST, true);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_POSTFIELDS, sendData);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_POSTFIELDSIZE,
sendData.Length);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_SSL_VERIFYPEER, false);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_SSL_VERIFYHOST, 1);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_TIMEOUT, timeout);

//set ssl params
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_CAINFO, pathToBundle);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_SSLCERT, pathToPem);
easy.SetOpt(DotNetCurl.CURLoption.CURLOPT_SSLCERTPASSWD, pemPassword);

//send
DotNetCurl.CURLcode cc = easy.Perform();

//get http response code
easy.GetInfo(DotNetCurl.CURLINFO.CURLINFO_RESPONSE_CODE, ref
httpResponseCode);

//cleanup & return
easy.Cleanup();

return cc;
////////////////////////////////////////////////////////////////////

So that's the problem, does anybody have any ideas on how to resolve it?
Received on 2007-02-20