Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl_easy_perform blocking infinitely #2761

Closed
Artenuvielle opened this issue Jul 19, 2018 · 4 comments
Closed

curl_easy_perform blocking infinitely #2761

Artenuvielle opened this issue Jul 19, 2018 · 4 comments
Labels
performance Windows Windows-specific

Comments

@Artenuvielle
Copy link

I am trying to build a dynamic loadable library on windows x64 with Visual Studio 2017. With this library I link a statically compiled version of libcurl (based on this commit, build options: nmake /f Makefile.vc mode=static MACHINE=x64 DEBUG=yes).

This is the code I'm running in my library:

#include "curl/curl.h"

#pragma comment(lib, "crypt32")
#pragma comment(lib, "ws2_32")
#pragma comment(lib, "Normaliz")
#pragma comment(lib, "wldap32")
void HTTPTest::init() {
	CURL *curl;
	CURLcode res;

	LOG("curl = curl_easy_init();\n");
	curl = curl_easy_init();
	if (curl)
	{
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1l);
		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
		curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);
		curl_easy_setopt(curl, CURLOPT_ACCEPTTIMEOUT_MS, 5000);
		curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
		res = curl_easy_perform(curl);

		if (res != CURLE_OK) {
			LOG("curl_easy_perform() failed: ", curl_easy_strerror(res));
		} else {
			LOG("\nGET sucessful.\n");
		}

		curl_easy_cleanup(curl);
	}
}

When executing this code it runs up to the curl_easy_perform and stays in there forever, never returning any value. When debugging the curl_easy_perform function I went into the easy_transfer function and on its second cycle I get stuck in curl_multi_perform > multi_runsingle > multi_done > Curl_resolver_wait_resolv > Curl_thread_join > WaitForSingleObjectEx. Am I missing something in my code or is there a bug in libcurl which seems to cannot end the thread for resolving the dns?

@jay
Copy link
Member

jay commented Jul 19, 2018

What do you mean by infinite, how long did you wait? multi_done waits on the resolve to complete so it can block waiting for getaddrinfo to return

curl/lib/multi.c

Lines 536 to 539 in db2ac90

if(data->mstate == CURLM_STATE_WAITRESOLVE) {
/* still waiting for the resolve to complete */
(void)Curl_resolver_wait_resolv(conn, NULL);
}

@Artenuvielle
Copy link
Author

I let it run for about 10 minutes one time and still nothing happened. I noticed that curl_easy_perform does not get stuck when I try to access an URL by ipv4 or ipv6, both work. I guess there is an issue with the DNS lookup going on.

@bagder bagder added the Windows Windows-specific label Jul 20, 2018
@bagder
Copy link
Member

bagder commented Jul 20, 2018

So can you resolve the host name with other tools? Does the curl command line tool work when given this URL? Can you show us the verbose output your program gets up to the point it "hangs" ?

@Artenuvielle
Copy link
Author

I have no idea why, but as I tried getting the output today it magically worked. Maybe it had something to do with restarting Visual Studio and/or my system. I think we can close this issue for now and when it reappears I will create a new one and refer here.

On a sidenote: I know that the command line tool of the same curl build was working correctly and could resolve domain names properly.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
performance Windows Windows-specific
Development

No branches or pull requests

3 participants