From nobody@FreeBSD.org  Thu Dec  7 14:34:11 2000
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 83E5737B401
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Dec 2000 14:34:11 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id eB7MYBv07910;
	Thu, 7 Dec 2000 14:34:11 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200012072234.eB7MYBv07910@freefall.freebsd.org>
Date: Thu, 7 Dec 2000 14:34:11 -0800 (PST)
From: chrisp@netwinsite.com
Sender: nobody@FreeBSD.org
To: freebsd-gnats-submit@FreeBSD.org
Subject: gethostbyaddr takes longer or locks up and burns cpu when linked to -pthread
X-Send-Pr-Version: www-1.0

>Number:         23364
>Category:       misc
>Synopsis:       gethostbyaddr takes longer or locks up and burns cpu when linked to -pthread
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 07 14:40:01 PST 2000
>Closed-Date:    Sat Nov 30 17:53:15 PST 2002
>Last-Modified:  Sat Nov 30 17:53:15 PST 2002
>Originator:     Chris Pugmire
>Release:        4.1.1-RELEASE
>Organization:
NetWin Ltd
>Environment:
FreeBSD news.siscom.net 4.1.1-RELEASE FreeBSD 4.1.1-RELEASE #2: Mon Nov 27 14:21:06 EST 2000     root@news.siscom.net:/usr/src/sys/compile/GENERIC  i386

>Description:
With a test program doing ip number to name lookups for a number that
does not have an entry if the program is linked with -pthread then
it takes 30 seconds longer and burns 100% cpu until it times out.

I believe it sometimes never times out or takes much longer but cannot
reproduce this in a test case.

Note that no actual threads are used, this program is simply linked
with -pthread and then behaves in this odd way.

>How-To-Repeat:
Sample code included:

(include headers...)
int do_reverse(char *ipnum);
int main(int argc, char *argv[])
{
	int i;
	if (argc<2) {
usage:		printf("Usage: testdns -rev n.n.n.n\n");
		return 0;
	}
	tcp_startup();
	for (i=1; i<argc; i++) {
		if (strncmp(argv[i],"-rev",4)==0) {
			do_reverse(argv[++i]);
		} else {
			printf("Invalid option (%s)\n",argv[i]);	
			goto usage;
		}
	}
	return 0;
}
int do_reverse(char *ipnum)
{
        struct sockaddr_in sin;
        struct hostent *hp;
	int start;
	start = time(NULL);

	sin.sin_addr.s_addr = inet_addr(ipnum);
	printf("Looking up (%s)\n",ipnum);
        hp = gethostbyaddr( (char *) &(sin.sin_addr), sizeof(sin.sin_addr), AF_INET);
	printf("Result %p\n",hp);
	if (hp!=NULL) if (hp->h_name!=NULL) {
		printf("result (%s)\n",hp->h_name);
	}
	printf("Delay %d seconds\n",time(NULL)-start);
	return TRUE;
}
Example output with the same program linked different ways:

news# ./testdns_nopthread -rev 160.79.54.12 
Looking up (160.79.54.12)
Result 0x0
Delay 80 seconds

news# ./testdns_pthread -rev 160.79.54.12
Looking up (160.79.54.12)
Result 0x0
Delay 111 seconds

(and in the second case watching top will show the testdns process
burning cpu)
>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: iedowse 
State-Changed-When: Sun Nov 18 08:10:21 PST 2001 
State-Changed-Why:  

Does this problem still occur with more recent releases? I can't 
reproduce it with FreeBSD 4.4. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23364 

From: Ian Dowse <iedowse@maths.tcd.ie>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: misc/23364: gethostbyaddr takes longer or locks up and burns cpu when linked to -pthread 
Date: Sat, 19 Jan 2002 20:42:50 +0000

 Adding a reply I had forgotten about to the audit trail:
 
 In message <5.1.0.14.2.20011120112559.04ae0bb0@ball>, Chris Pugmire writes:
 >
 >At 08:11 AM 11/18/01 -0800, you wrote:
 >>Synopsis: gethostbyaddr takes longer or locks up and burns cpu when linked 
 >>to -pthread
 >>
 >>State-Changed-From-To: open->feedback
 >>State-Changed-By: iedowse
 >>State-Changed-When: Sun Nov 18 08:10:21 PST 2001
 >>State-Changed-Why:
 >>
 >>Does this problem still occur with more recent releases? I can't
 >>reproduce it with FreeBSD 4.4.
 >>
 >>http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23364
 >
 >Hi, sorry I'm unable to reproduce it now, it originally occured on a customers
 >machine which I no longer have access to, I can't make it occur on our own
 >system now but I don't know if I ever reproduced it locally, it may be 
 >dependent
 >in some way on the dns server used I'm not sure.
 >
 >Sorry this isn't very helpful, all I can suggest is you check the code that
 >reads from the dns server to see if it can in any way loop while waiting for
 >a response, my guess would be if the thread library is somehow stopping a 
 >select
 >call from working correctly but it must be more subtle than that.
 >
 >Thanks for looking into it anyway I appreciate it.  It was several months
 >ago I reported this so sorry if I'm a bit shaky on the facts.
 >
 >         ChrisP.
 >

From: Archie Cobbs <archie@packetdesign.com>
To: freebsd-gnats-submit@FreeBSD.org, chrisp@netwinsite.com
Cc:  
Subject: Re: misc/23364: gethostbyaddr takes longer or locks up and burns cpu 
 when linked to -pthread
Date: Mon, 09 Sep 2002 15:45:24 -0700

 This bug (if it really happened) may have been fixed by the fix to
 bin/42175:
 
   http://www.freebsd.org/cgi/query-pr.cgi?pr=misc/23364
 
 It may have only happened when you configured /etc/resolv.conf to
 have an unreachable nameserver, so that the UDP query socket got
 an error such as ENETDOWN or something like that.
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com
State-Changed-From-To: feedback->closed 
State-Changed-By: iedowse 
State-Changed-When: Sat Nov 30 17:46:10 PST 2002 
State-Changed-Why:  

According to Archie Cobbs, this is probably the same problem 
as that in bin/42175, which has been fixed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23364 
>Unformatted:
