This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug network/16738] New: gai_suspend returns EAI_SYSTEM when timeout is hit and DONT_NEED_GAI_MISC_COND is defined


https://sourceware.org/bugzilla/show_bug.cgi?id=16738

            Bug ID: 16738
           Summary: gai_suspend returns EAI_SYSTEM when timeout is hit and
                    DONT_NEED_GAI_MISC_COND is defined
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
          Assignee: unassigned at sourceware dot org
          Reporter: rbraud at gmail dot com

This bug description is based on the source code in git revision
1ca2d03e3e4c8b27a666676bb5b92e6f5d6f2a07, although I first found it on Ubuntu
12.04, which uses a much older glibc version.

Problem:  gai_suspend returns EAI_SYSTEM instead of EAI_AGAIN when the supplied
timeout argument has been reached and DONT_NEED_GAI_MISC_COND is defined (which
seems to be the default).

In gai_suspend.c, we have:

#ifdef DONT_NEED_GAI_MISC_COND
      result = 0;
      GAI_MISC_WAIT (result, cntr, timeout, 1);
#else

Inside GAI_MISC_WAIT, we have:
status = lll_futex_timed_wait (futexaddr, oldval, timeout,          \
                   LLL_PRIVATE);              \
...
if (status == -EINTR)                              \
  result = EINTR;                              \
else if (status == -ETIMEDOUT)                          \
  result = EAGAIN;                              \
else                                      \
  assert (status == 0 || status == -EWOULDBLOCK);

So, if the futex wait timed out, result gets set to EAGAIN.  However, later on
in gai_suspend, we have:

if (result != 0)
  {
  /* An error occurred.  Possibly it's EINTR.  We have to translate
     the timeout error report of `pthread_cond_timedwait' to the
     form expected from `gai_suspend'.  */
  if (__builtin_expect (result, ETIMEDOUT) == ETIMEDOUT)
    result = EAI_AGAIN;
  else if (result == EINTR)
    result = EAI_INTR;
  else
    result = EAI_SYSTEM;
}

The code expects a timeout to correspond to result being set to ETIMEDOUT, but
it is EAGAIN, so result ends up as EAI_SYSTEM.  This seems incorrect to me.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]