public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mpoliwczak34 at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug network/29717] New: getaddrinfo returns EAI_NONAME with errno set to EMFILE.
Date: Sat, 22 Oct 2022 12:31:29 +0000	[thread overview]
Message-ID: <bug-29717-131@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 29717
           Summary: getaddrinfo returns EAI_NONAME with errno set to
                    EMFILE.
           Product: glibc
           Version: 2.36
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: network
          Assignee: unassigned at sourceware dot org
          Reporter: mpoliwczak34 at gmail dot com
  Target Milestone: ---

When running out of FDs the getaddrinfo returns EAI_NONAME (instead of
EAI_SYSTEM) and it sets errno to EMFILE. The man page says that the errno is
only set it the case where getaddrinfo returns EAI_SYSTEM. I tested it also
with musl libc and it returns the correct code: EAI_SYSTEM. It seems like a bug
in glibc.

#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <fcntl.h>


int lookup_host (const char *host) {
  struct addrinfo hints, *res, *result;
  int errcode;

  memset (&hints, 0, sizeof (hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags |= AI_CANONNAME;

  errcode = getaddrinfo (host, NULL, &hints, &result);
  if (errcode != 0) {
        if (errcode == EAI_SYSTEM) {
                printf("eai system\n");
                perror("getaddrinfo");
      return -1;
        }
        printf("not eai system\n");
        perror("getaddrinfo");
        return -1;
   }

  freeaddrinfo(result);
  return 0;
}

int main (void) {
        for (int i = 0; i < 100; i++) {
                open("/tmp",O_WRONLY|O_TMPFILE,0640);
        }

        char* inbuf = "go.dev";
        lookup_host(inbuf);
}

Glibc:
[mateusz@arch code ]$ gcc main.c && bash -c 'ulimit -n 50 && ./a.out'
not eai system
getaddrinfo: Too many open files

Musl libc:
[mateusz@arch code ]$ musl-gcc main.c && bash -c 'ulimit -n 50 && ./a.out'
eai system
getaddrinfo: No file descriptors available

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

             reply	other threads:[~2022-10-22 12:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22 12:31 mpoliwczak34 at gmail dot com [this message]
2022-10-24 10:32 ` [Bug network/29717] " fweimer at redhat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-29717-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).