From ishizuka@ish.org  Tue Aug 15 04:47:19 2000
Return-Path: <ishizuka@ish.org>
Received: from onion.ish.org (onion.ish.org [210.145.219.202])
	by hub.freebsd.org (Postfix) with ESMTP id F091337B563
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 Aug 2000 04:47:11 -0700 (PDT)
	(envelope-from ishizuka@ish.org)
Received: (from ishizuka@localhost)
	by onion.ish.org (8.9.3/3.7Wpl2-2000/05/28) id UAA17919;
	Tue, 15 Aug 2000 20:47:09 +0900 (JST)
Message-Id: <200008151147.UAA17919@onion.ish.org>
Date: Tue, 15 Aug 2000 20:47:09 +0900 (JST)
From: ishizuka@ish.org
Reply-To: ishizuka@ish.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: fetch -T n is not timeout correctly
X-Send-Pr-Version: 3.2

>Number:         20613
>Category:       bin
>Synopsis:       fetch -T n is not timeout correctly when target server is down
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 15 04:50:00 PDT 2000
>Closed-Date:    Wed Nov 27 07:45:44 PST 2002
>Last-Modified:  Wed Nov 27 07:45:44 PST 2002
>Originator:     Masachika ISHIZUKA
>Release:        FreeBSD 4.1-RELEASE i386
>Organization:
>Environment:

>Description:

	% fetch -T 5 http://www.hoge.com/index.html

	When server 'www.hoge.com' is down or can't lookup address from
	DNS server, fetch command is not timeout with 5 seconds.
	Older version of fetch (with 4.0R or 3.4R) is timeout with 5 seconds.

>How-To-Repeat:

	

>Fix:

	


>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: ishizuka@ish.org
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, des@freebsd.org
Subject: Re: bin/20613: fetch -T n is not timeout correctly
Date: Wed, 16 Aug 2000 02:48:58 +1000 (EST)

 On Tue, 15 Aug 2000 ishizuka@ish.org wrote:
 
 > >Description:
 > 
 > 	% fetch -T 5 http://www.hoge.com/index.html
 > 
 > 	When server 'www.hoge.com' is down or can't lookup address from
 > 	DNS server, fetch command is not timeout with 5 seconds.
 > 	Older version of fetch (with 4.0R or 3.4R) is timeout with 5 seconds.
 
 This reminded me of an old problem with ping(8).  ^C doesn't work for
 killing ping when DNS lookup hangs, provided you wait a second or two
 for execution to reach res_send().  This is because res_send() retries
 after EINTR, so it doesn't work with signal handlers that just set a
 flag.  ping's SIGINT handler was fixed a few years ago to just set a
 flag (previously it called stdio functions).
 
 The problem in fetch(1) seems to be the same.  fetch's SIGINT and
 SIGALRM handlers just set a flag, so neither -T nor ^C can be used to
 kill fetch when DNS lookup hangs.
 
 ping's SIGALRM handler also just sets a flag, but this works right
 because ping only uses alarms to control syscalls and EINTR works
 right for syscalls.
 
 Bruce
 
 
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Aug 16 01:03:48 PDT 2000 
Responsible-Changed-Why:  
Over to the maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20613 

From: Hajimu UMEMOTO <ume@mahoroba.org>
To: ishizuka@ish.org
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, des@freebsd.org,
	ume@mahoroba.org
Subject: Re: bin/20613: fetch -T n is not timeout correctly
Date: Thu, 17 Aug 2000 02:52:50 +0900 (JST)

 On Tue, 15 Aug 2000 ishizuka@ish.org wrote:
 
 > >Description:
 > 
 >  % fetch -T 5 http://www.hoge.com/index.html
 > 
 >  When server 'www.hoge.com' is down or can't lookup address from
 >  DNS server, fetch command is not timeout with 5 seconds.
 >  Older version of fetch (with 4.0R or 3.4R) is timeout with 5 seconds.
 
 I cannot realize this problem with accessing
 http://www.hoge.com/index.html.  However, I heared from you that
 fetching to the server where is actually not exist something like
 "fetch -T 1 http://10.1.1.1/aaa.txt" causes this problem.
 Is this patch fix your problem?
 
 Index: lib/libfetch/common.c
 diff -u lib/libfetch/common.c.orig lib/libfetch/common.c
 --- lib/libfetch/common.c.orig	Tue Jul 18 07:01:26 2000
 +++ lib/libfetch/common.c	Thu Aug 17 02:36:42 2000
 @@ -201,7 +201,12 @@
  	if ((sd = socket(res->ai_family, res->ai_socktype,
  			 res->ai_protocol)) == -1)
  	    continue;
 -	if (connect(sd, res->ai_addr, res->ai_addrlen) != -1)
 +	if (fetchTimeout)
 +	    alarm(fetchTimeout);
 +	err = connect(sd, res->ai_addr, res->ai_addrlen);
 +	if (fetchTimeout)
 +	    alarm(0);
 +	if (err != -1)
  	    break;
  	close(sd);
  	sd = -1;
 
 --
 Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
 ume@mahoroba.org  ume@bisd.hitachi.co.jp  ume@FreeBSD.org
 http://www.imasy.org/~ume/
 

From: Masachika ISHIZUKA <ishizuka@ish.org>
To: FreeBSD-gnats-submit@FreeBSD.ORG, des@freebsd.org
Cc:  
Subject: Re: bin/20613: fetch -T n is not timeout correctly
Date: Thu, 17 Aug 2000 09:39:16 +0900

 >>>Description:
 >> 
 >>  % fetch -T 5 http://www.hoge.com/index.html
 >> 
 >>  When server 'www.hoge.com' is down or can't lookup address from
 >>  DNS server, fetch command is not timeout with 5 seconds.
 >>  Older version of fetch (with 4.0R or 3.4R) is timeout with 5 seconds.
 > 
 > I cannot realize this problem with accessing
 > http://www.hoge.com/index.html.  However, I heared from you that
 > fetching to the server where is actually not exist something like
 > "fetch -T 1 http://10.1.1.1/aaa.txt" causes this problem.
 > Is this patch fix your problem?
 > 
 > Index: lib/libfetch/common.c
 > diff -u lib/libfetch/common.c.orig lib/libfetch/common.c
 > --- lib/libfetch/common.c.orig	Tue Jul 18 07:01:26 2000
 > +++ lib/libfetch/common.c	Thu Aug 17 02:36:42 2000
 > @@ -201,7 +201,12 @@
 >  	if ((sd = socket(res->ai_family, res->ai_socktype,
 >  			 res->ai_protocol)) == -1)
 >  	    continue;
 > -	if (connect(sd, res->ai_addr, res->ai_addrlen) != -1)
 > +	if (fetchTimeout)
 > +	    alarm(fetchTimeout);
 > +	err = connect(sd, res->ai_addr, res->ai_addrlen);
 > +	if (fetchTimeout)
 > +	    alarm(0);
 > +	if (err != -1)
 >  	    break;
 >  	close(sd);
 >  	sd = -1;
 
   Hi, this is ishizuka.
   Thank you very much.  This patch fixed my problem.
 And, sorry to say that I wrote 'www.hoge.com' to mean
 'some.nonexist.domain.or.server' but this domain and this
 server really exists.
 
 -- 
 ishizuka@ish.org
 

From: Dag-Erling Smorgrav <des@flood.ping.uio.no>
To: Bruce Evans <bde@zeta.org.au>
Cc: ishizuka@ish.org, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/20613: fetch -T n is not timeout correctly
Date: 30 Aug 2000 11:10:22 +0200

 I'm aware of the problem, but not quite sure how to handle it. The
 timeout should be enforced by libfetch, not by fetch(1), but I can't
 see any easy way of doing it.
 
 DES
 -- 
 Dag-Erling Smorgrav - des@flood.ping.uio.no
 
State-Changed-From-To: open->feedback 
State-Changed-By: des 
State-Changed-When: Tue Oct 29 01:31:08 PST 2002 
State-Changed-Why:  
Fixed in -CURRENT, awaiting MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20613 
State-Changed-From-To: feedback->closed 
State-Changed-By: des 
State-Changed-When: Wed Nov 27 07:45:43 PST 2002 
State-Changed-Why:  
Fixed, thanks. 

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