From john@starfire.mn.org  Sun May 18 16:56:19 1997
Received: from starfire.mn.org (root@starfire.skypoint.net [199.86.32.187])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA21598
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 18 May 1997 16:56:17 -0700 (PDT)
Received: (from john@localhost)
	by starfire.mn.org (8.8.5/1.1)  id SAA10521; Sun, 18 May 1997 18:57:01 -0500 (CDT)
Message-Id: <199705182357.SAA10521@starfire.mn.org>
Date: Sun, 18 May 1997 18:57:01 -0500 (CDT)
From: john@starfire.mn.org
Reply-To: john@starfire.mn.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: gethostbyname fails for file descriptors above 255
X-Send-Pr-Version: 3.2

>Number:         3622
>Category:       bin
>Synopsis:       gethostbyname fails for file descriptors above 255
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 18 17:00:01 PDT 1997
>Closed-Date:    Sun Apr 12 09:14:41 PDT 1998
>Last-Modified:  Sun Apr 12 09:15:05 PDT 1998
>Originator:     John Lind
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
Starfire Consulting Services, SkyPoint Communications, Inc.
>Environment:

	

>Description:

gethostbyname() fails for a perfectly good domain name once a program
already has file descriptors 0-255 open.  I have not yet tracked
this down to find if it is specific to gethostbyname, or if it
may be the underlying infrastructure, or possibly even into the kernel
(in which case the category specified for this report will be wrong).

>How-To-Repeat:

The following program will reproduce the problem.  Sample output
is given.  Note that the same lookup is performed successfully
253 times before it fails.
--- sample output
www.freebsd.org: Unknown host
RLIMIT_NOFILE rlim_cur 2088
252: 255, /tmp/testghbn.02985
--- program source for testghlim.c
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>

int
test_ghbn(const char *dhn)
{
    struct hostent *h;
    extern int h_errno;

    if( (h = gethostbyname(dhn)) == NULL ) {
	herror(dhn);
	return 1;
    }
    return 0;
}

char *progname;

void usage()
{
    fprintf(stderr,"Usage: %s host.domain.name\n");
    exit(99);
}

main(int argc, char **argv)
{
    int idx;
    int fd;
    struct rlimit info;
    char tfn[32];
    char *hostdn;

    progname = *argv;

    if (argc < 2)
	usage();

    hostdn = argv[1];

    getrlimit(RLIMIT_NOFILE,&info);
    info.rlim_cur = info.rlim_max;
    setrlimit(RLIMIT_NOFILE,&info);
    getrlimit(RLIMIT_NOFILE,&info);
    printf("RLIMIT_NOFILE rlim_cur %d\n",info.rlim_cur);

    for (idx=0; idx < 300; idx++) {
	strcpy(tfn,"/tmp/testghbn.XXXXX");
	fd = mkstemp(tfn);
	unlink(tfn);
	if (test_ghbn(hostdn)) {
		printf("%d: %d, %s\n", idx, fd, tfn);
		break;
		}
	}
    exit(0);
    }

>Fix:
	
	No known fix at this time.  As I urgently need this to work to
	get Apache 1.1.3 or 1.2b10 running for a multi-homed web site
	of about 300 virtual hosts, I will begin attempting to build
	debugging versions of the standard library routines as soon
	as I find something to eat...

>Release-Note:
>Audit-Trail:

From: Robert Blayzor <robert@superior.net>
To: freebsd-gnats-submit@freebsd.org, john@starfre.mn.org
Cc:  Subject: Re: bin/3622: gethostbyname fails for file descriptors over 255
Date: Mon, 15 Dec 1997 18:18:49 -0500 (EST)

 I would like to confirm this problem, even on 2.2.5-RELEASE and 2.2.5-STABLE
 as of 12-14-97.
 
 We have programs such a Squid, Popper 2.4, which are either failing or giving
 warnings that hostnames cannot be resolved.  Appears to be when there are may
 system file descriptors in use.  Squid 1.1.18 will not even run as DNS cannot
 be used, this problem is serious and needs a fix ASAP.
 
 When tracking the problem with herror(gethostbyname()), problem returns
 "host unknown" even though using nslookup, dig, or system DNS (named), query
 returns fine.
 
 Problem is easy to reproduce.
 
 -- 
  Robert Blayzor     	  robert@superior.net    Telecon Communications
  MIS/Programmer/Admin      Network Engineer          131 Enterprise Rd.
  Superior Net Services	     518-762-3456           Johnstown, NY 12095
               "FreeBSD!  Turning PC's into Workstations!"
State-Changed-From-To: open->feedback 
State-Changed-By: phk 
State-Changed-When: Sun Apr 12 04:32:55 PDT 1998 
State-Changed-Why:  
I have tried to reproduce this on a -current system and couldn't, 
is this still a problem in 2.26 ? 

From: Peter Wemm <peter@netplex.com.au>
To: Poul-Henning Kamp <phk@FreeBSD.ORG>
Cc: john@starfire.mn.org, freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/3622 
Date: Sun, 12 Apr 1998 21:06:54 +0800

 Poul-Henning Kamp wrote:
 > Synopsis: gethostbyname fails for file descriptors above 255
 > 
 > State-Changed-From-To: open->feedback
 > State-Changed-By: phk
 > State-Changed-When: Sun Apr 12 04:32:55 PDT 1998
 > State-Changed-Why: 
 > I have tried to reproduce this on a -current system and couldn't,
 > is this still a problem in 2.26 ?
 
 This is fixed in -current because poll() has no descriptor limits.
 
 In -stable, it was fixed in 1.10.2.3 where the descriptor table is 
 malloc'ed if necessary.  select() in -stable was changed to allow 
 effectively unlimited fd_set sizes in rev 1.19, which was just prior to 
 the RELENG_2_2 branchpoint.  It should be well and truely fixed there too.
 
 The only "problem" is old binaries linked with a 2.1.x libc or statically 
 linked where res_send.c does not know how to feed larger fd_set's into 
 select().
 
 Cheers,
 -Peter
 --
 Peter Wemm <peter@netplex.com.au>   Netplex Consulting
 
 
State-Changed-From-To: feedback->closed 
State-Changed-By: phk 
State-Changed-When: Sun Apr 12 09:14:41 PDT 1998 
State-Changed-Why:  
fixed 
>Unformatted:
