NetBSD Problem Report #15174

Received: (qmail 26520 invoked from network); 8 Jan 2002 03:04:28 -0000
Message-Id: <200201080303.g0833mG01571@guava.araneus.fi>
Date: Mon, 7 Jan 2002 19:03:48 -0800 (PST)
From: gson@nominum.com
Reply-To: gson@nominum.com
To: gnats-bugs@gnats.netbsd.org
Subject: gdb "kill" command does not free sockets
X-Send-Pr-Version: 3.95

>Number:         15174
>Category:       bin
>Synopsis:       gdb "kill" command does not free sockets
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 08 03:05:00 +0000 2002
>Closed-Date:    Thu Apr 14 14:46:26 +0000 2016
>Last-Modified:  Thu Apr 14 14:46:26 +0000 2016
>Originator:     Andreas Gustafsson
>Release:        NetBSD 1.5Z
>Organization:
Nominum Inc
>Environment:
System: NetBSD guava.araneus.fi 1.5Z NetBSD 1.5Z (GUAVA) #0: Sat Dec 15 20:49:20 PST 2001 gson@guava.araneus.fi:/usr/src/sys/arch/i386/compile/GUAVA i386
Architecture: i386
Machine: i386
>Description:

When using gdb to debug a program that listens on one or more sockets,
killing the program using the gdb "kill" command does not cause the
sockets to be fully freed as they would be if the process exited.  If
the program is then restarted using the "run" command, it will be
unable to bind to the sockets as they are "already in use".  This
makes debugging network daemons under NetBSD awkward.

This bug affects at least NetBSD 1.4 and 1.5, on i386 and sparc.
It does not matter whether the SO_REUSEADDR socket option is set.

On other operating systems, gdb does *not* exhibit this behavior.

>How-To-Repeat:

    $ cat test.c
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <err.h>

    main() {
	    int s, r;
	    struct sockaddr_in local;
	    struct sockaddr_in remote;
	    socklen_t len;

	    memset(&local, 0, sizeof local);
	    local.sin_port = htons(5555);

	    s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	    if (s < 0)
		    err(1, "socket");
	    r = bind(s, (struct sockaddr *) &local, sizeof local);
	    if (r < 0)
		    err(1, "bind");
	    r = listen(s, 5);
	    if (r < 0)
		    err(1, "listen");
	    accept(s, (struct sockaddr *) &remote, &len);
    }
    $ cc -g test.c
    $ gdb a.out
    GNU gdb 5.0-nb1
    Copyright 2000 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-unknown-netbsdelf"...
    (gdb) run
    Starting program: /usr/s/u/gson/bugs/netbsd/gdb.kill/a.out 
    ^C
    Program received signal SIGINT, Interrupt.
    0x480aa2ab in accept () from /usr/lib/libc.so.12
    (gdb) kill
    Kill the program being debugged? (y or n) y
    (gdb) run
    Starting program: /usr/s/u/gson/bugs/netbsd/gdb.kill/a.out 
    a.out: bind: Address already in use

    Program exited with code 01.
    (gdb)

>Fix:

Unknown.  As a workaround, use the gdb commands "signal SIGKILL"
and "continue" instead of "kill". 
>Release-Note:
>Audit-Trail:

From: Love <lha@stacken.kth.se>
To: gnats-bugs@netbsd.org
Cc: gson@nominum.com
Subject: Re: bin/15174
Date: 21 Oct 2002 03:03:10 +0200

 Ok, ptrace(PT_KILL) cause the process to stop in issignal() and gdb doesn't
 expect that. All other ptrace base OS that I could find didn't cause this
 to happen (Solaris, DUX4.0d, linux, darwin), execpt NetBSD and FreeBSD
 (don't have OpenBSD machines installed after the move yet)

 So, in the first solution, we patch gdb an claim that
 ptrace(PT_CONTINUE,....,SIGFOO) will cause the traced process to wait in
 issignal(), and since PT_KILL is documented to do the same thing as
 PT_CONTINUE with signo, gdb is wrong.

 http://www.e.kth.se/~lha/patches/netbsd/gdb-kill

 Else we can do like everyone (except *BSD) and let PT_KILL just kill the
 process and not stop it in issignal(), but the documentation is then wrong.

 http://www.e.kth.se/~lha/patches/netbsd/gdb-kill-kernel

 I've not yet checked if ptrace(PT_CONTINUE, ..., SIGFOO) will stop the
 process in not-*BSD OS-s. Need to do that.
State-Changed-From-To: open->analyzed 
State-Changed-By: lha 
State-Changed-When: Sun Oct 20 18:34:13 PDT 2002 
State-Changed-Why:  
analyzed the problem, two fixes, one to gdb, one to kernel 
each fixes the problem. need feedback from others which to choose 
. 


Responsible-Changed-From-To: bin-bug-people->lha 
Responsible-Changed-By: lha 
Responsible-Changed-When: Sun Oct 20 18:34:13 PDT 2002 
Responsible-Changed-Why:  
I'll make sure this get fixed 
Responsible-Changed-From-To: lha->bin-bug-people
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Wed, 02 Dec 2009 23:30:44 +0000
Responsible-Changed-Why:
lha is observer now, shouldn't be held responsible


From: Andreas Gustafsson <gson@gson.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/15174: gdb "kill" command does not free sockets
Date: Thu, 14 Apr 2016 17:44:55 +0300

 The test program in the PR needs a

   local.sin_family = AF_INET;

 to run under -current.  With that change, the test fails to reproduce
 the problem under -current/amd64 (or 7.0 or 6.1.5, for that matter),
 so it looks like it has been fixed some time ago.
 -- 
 Andreas Gustafsson, gson@gson.org

State-Changed-From-To: analyzed->closed
State-Changed-By: gson@NetBSD.org
State-Changed-When: Thu, 14 Apr 2016 14:46:26 +0000
State-Changed-Why:
Problem no longer occurs.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.