cURL / Mailing Lists / curl-library / Single Mail

curl-library

[bug report] Windows multithreading problem - couldn't resolve host

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 22 Feb 2009 19:50:33 +0100 (CET)

Hey friends

Here's yet another windows-specific bug report that I need help to sort out.
I'm under the impression lots of Windows apps already use libcurl fine in
multithread situations so I don't quite understand why this guy has a problem
all of a sudden...

Feel free to respond here, or in the tracker. Though I doubt the submitter
subscribes to/read this mailing list.

-- 
  / daniel.haxx.se
Bugs item #2627315, was opened at 2009-02-22 05:19
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2627315&group_id=976
Initial Comment:
I use libcurl 7.19.2 precompiled for mingw. When I use multiple threads 
function curl_easy_perform() returns CURLE_COULDNT_RESOLVE_HOST. When I use 
critical sections to serialize CURL calls it doesn't help also. With one 
thread only my code works well.
----------------------------------------------------------------------
Comment By: mybugaccount mybugaccount (mybugaccount)
Date: 2009-02-22 07:58
Message:
Ok, there is the source code compiled with mingw 3.4.2 and linked with
libcurldll.a (7.19.2).
Only the first thread runs fine, two others returns
CURLE_COULDNT_RESOLVE_HOST.
#include <windows.h>
#include <curl/curl.h>
static size_t wd_null(void *ptr, size_t size, size_t nmemb, void *stream)
{
 	return size*nmemb;
}
DWORD WINAPI threadFunc(LPVOID param)
{
 	int *p=(int*)param;
 	int id=*p;
 	char user[1024];
 	char pass[1024];
 	if (id==0)
 	{
 		strcpy(user,"user0");
 		strcpy(pass,"pass0");
 	}
 	if (id==1)
 	{
 		strcpy(user,"user1");
 		strcpy(pass,"pass1");
 	}
 	if (id==2)
 	{
 		strcpy(user,"user2");
 		strcpy(pass,"pass2");
 	}
 	CURL *curl;
     curl = curl_easy_init();
     if (curl)
     {
       	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1)");
         curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
     }
     else
     {
        return 0;
     }
 	CURLcode res;
 	char post_login[1024];
 	sprintf(post_login,"login=%s&password=%s",user,pass);
 	// here the original address was replaced with www.google.com,
 	// but the code still returns the same error
 	curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/login");
 	curl_easy_setopt(curl, CURLOPT_POST, 1);
 	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_login);
     curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(post_login));
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wd_null);
     res = curl_easy_perform(curl);
     if (res!=0)
     {
 		char msg[1024];
 		sprintf(msg,"error %d in thread %d\n",res,id);
 		MessageBox(0,msg,"err",MB_OK);
 	}
 	return 1;
}
int main()
{
 	int id0,id1,id2;
 	id0=0;
 	id1=1;
 	id2=2;
 	DWORD threadid1,threadid2,threadid3;
 	HANDLE h1=CreateThread(0,1024*1024,threadFunc,&id0,0,&threadid1);
 	HANDLE h2=CreateThread(0,1024*1024,threadFunc,&id1,0,&threadid2);
 	HANDLE h3=CreateThread(0,1024*1024,threadFunc,&id2,0,&threadid3);
 	Sleep(10000);
 	return 0;
}
----------------------------------------------------------------------
Comment By: Daniel Stenberg (bagder)
Date: 2009-02-22 07:18
Message:
This kind of generic report is next to useless. We have a large amount of
users who use libcurl in threaded apps with no problems.
Please back up your claims with facts, most preferably with a small fully
working source code that reproduces it.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2627315&group_id=976
Received on 2009-02-22