alarm() does not interrupt gethostbyname() in RTEMS #5

Open
sbourdeauducq opened this Issue May 3, 2011 · 11 comments

Comments

Projects
None yet
2 participants
Owner

sbourdeauducq commented May 3, 2011

Symptom: libcurl connect timeout does not work
Using CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT has no effect. Transfers that should be interrupted by timeouts are not.
Those features are needed in Flickernoise so that the render mode can be cleanly exited when the RSS wall is enabled with a server that does not respond.
See commit m-labs/flickernoise@1c8d4a5

Owner

sbourdeauducq commented May 30, 2011

This will also cause problems with the web update.

Collaborator

xiangfu commented Jun 10, 2011

by googling some info about curl_easy_setopt, the CURLOPT_TIMEOUT includes CURLOPT_CONNECTTIMEOUT,
from the manual: http://php.net/manual/en/function.curl-setopt.php
CURLOPT_CONNECTTIMEOUT The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
CURLOPT_TIMEOUT The maximum number of seconds to allow cURL functions to execute.

http://curl.haxx.se/mail/lib-2010-06/0055.html

Collaborator

xiangfu commented Jun 10, 2011

I tried add this patch to flash.c:

diff --git a/src/flash.c b/src/flash.c
index c3ef176..f9ad280 100644
--- a/src/flash.c
+++ b/src/flash.c
@@ -109,6 +109,10 @@ static int download(const char *url, const char *filename)
        curl = curl_easy_init();
        if (curl) {
                curl_easy_setopt(curl, CURLOPT_URL, url);
+
+               curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5);
+               curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
+
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

after 10 seconds, it give me 'Failed to downloda bitstream'

I needs find a way to test CONNECTTIMEOUT...

Collaborator

xiangfu commented Jun 10, 2011

I tried change it to "curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180)", while 'web update', I unplug the network cable. after ~3 mins, it give me 'Failed to downloda bitstream'.

Owner

sbourdeauducq commented Jun 10, 2011

Hmm, how about this:

  • connect M1 to the internet
  • enable twitter wall
  • render some patch
  • unplug ethernet cable
  • wait a bit (so the M1 tries to refresh tweets)
  • try to stop rendering... last time I tried, it could not stop as it was blocked on a libcurl call that never timed out
Owner

sbourdeauducq commented Jun 10, 2011

Just tested - problem is still present even after your commit.

xiangfu was assigned Jun 11, 2011

Collaborator

xiangfu commented Jun 15, 2011

after change the identi.ca to it's IP address: 174.142.114.102, the libcurl timeout works just fine.

I got message from libcurl(after set CURLOPT_VERBOSE)

  • Curl_ipv4_resolve_r failed for identi.ca
  • Couldn't resolve host 'identi.ca'
  • Closing connection #0
  • Couldn't resolve host name

seems the timeout not include the DNS resolving.

Collaborator

xiangfu commented Jun 15, 2011

I almost sure there is something wrong with 'gethostbyname' function, sometimes works. sometimes it return 0(for return 0, it needs a lot of time ~2mins, that is why flickernoise not exit rendering, waiting gethostbyname finished), I tried ~10 mins with enable rsswall,

then I try to port the c-ares http://c-ares.haxx.se/, but after link the c-ares, it's always give timeout.

Owner

sbourdeauducq commented Jun 15, 2011

IMO the best way is to fix gethostbyname, instead of throwing in a redundant implementation of a DNS resolver that does not work either. So please debug the gethostbyname function... you can also ask around on the RTEMS mailing list.

Owner

sbourdeauducq commented Jun 15, 2011

gethostbyname should be interrupted by POSIX signals...

Collaborator

xiangfu commented Jun 21, 2011

alarm() should work anyway in gethostbyname().(for TIMEOUT in libcurl)
we have a workaround, make sure the gethostbyname() finished in 15 seconds
m-labs/flickernoise@fffa076

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment