Skip to contentSkip to conversation

inconsistency in thread/signal interaction in 2.6.5 and previous vs. 2.6.6 and later (possibly a bug?)

DISCUSSION Glyph Lefkowitz 4 participants 5 messages Aug 16, 2004

lore
Share & tools
lore
#0 lore raw

Hello Kernel People,

Firstly, here is a brief example of some code that behaves very differently on 2.6.5 and 2.6.6:

http://www.twistedmatrix.com/users/glyph/signal-bug.c

I have verified that it says "Completed" on kernel 2.6.5, 2.6.3 and 2.6.1, and says "Died" on 2.6.6, 2.6.7 and 2.6.8.1, so I am pretty sure the difference is between 2.5.6 and 2.6.6.

As far as I understand it, kernel 2.6.5 would not deliver a signal to anyone upon thread termination, but kernel 2.6.6 will deliver a SIGHUP to the process's main thread, if the multi-threaded process's controlling terminal is a pty.

This is most likely a muddled explanation, and it is certainly incomplete. Please read the code to see what I mean. I am not the sort of person who would normally be posting to the kernel mailing list, or even writing code in C, for that matter.

I upgraded to the debian kernel 2.6.7 from 2.6.5; this had the unfortunate side-effect of breaking Emacs integration with my unit tests. It also seems to cause certain problems with the Conch SSH server ( http://www.twistedmatrix.com/products/conch ) but I believe emacs has rather a larger installed base.

Before anyone else has to tell me - yes, I am well aware that I should not be sticking my hand into the signals/threads interaction blender if I can avoid it, but in this case I can't :-).

On 2.6.5 and previous, the unit tests would run correctly; they all passed. On 2.6.7, the tests would run correctly *on a terminal*, but they would fail about halfway through if run in a 'M-x compile' buffer in emacs. Coincidentally, they would fail at about the point where one of the tests spawned a few threads to test the thread-safety of an API, then immediately shut them down as part of the test-cleanup. Kaboom.

If it helps to know, asynchronous processes in emacs (e.g. M-x compile, eshell) will get a SIGHUP if a thread terminates, but synchronous processes (e.g. M-x shell-command, C-c C-c in a Python buffer) will not. The critical difference between these *seems* to be the creation of a PTY for a controlling terminal.

I am sorry I cannot accompany this with a patch to fix it. I am curious though, is this even a bug, or just a stricter reading of some POSIX threading standard?

#1 lore raw

On Mon, 16 Aug 2004 06:01:05 -0400
Glyph Lefkowitz <[email protected]> bubbled:

Quoted 11 lines

Hello Kernel People,

Firstly, here is a brief example of some code that behaves very differently on 2.6.5 and 2.6.6:

http://www.twistedmatrix.com/users/glyph/signal-bug.c

I have verified that it says "Completed" on kernel 2.6.5, 2.6.3 and 2.6.1, and says "Died" on 2.6.6, 2.6.7 and 2.6.8.1, so I am pretty sure the difference is between 2.5.6 and 2.6.6.

FYI:

# gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
# cat /proc/version 
Linux version 2.6.8-rc2-mm1 (root@phoebee) (gcc version 3.3.3 20040412
(Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)) #1 Wed Jul 28 11:39:48
CEST 2004
Signature · 9 lines
MyExcuse:
Flat tire on station wagon with tapes.  ("Never underestimate the
bandwidth of a station wagon full of tapes hurling down the highway"
Andrew S. Tannenbaum)

Martin Zwickel <[email protected]>
Research & Development

TechnoTrend AG <http://www.technotrend.de>
#2 lore raw
Quoted 14 lines · Martin Zwickel

On Mon, 16 Aug 2004 06:01:05 -0400

Glyph Lefkowitz <[email protected]> bubbled:

Quoted 10 lines

Hello Kernel People,

Firstly, here is a brief example of some code that behaves very differently on 2.6.5 and 2.6.6:

http://www.twistedmatrix.com/users/glyph/signal-bug.c

I have verified that it says "Completed" on kernel 2.6.5, 2.6.3 and 2.6.1, and says "Died" on 2.6.6, 2.6.7 and 2.6.8.1, so I am pretty sure the difference is between 2.5.6 and 2.6.6.

Quoted 8 lines

FYI:

# gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
# cat /proc/version
Linux version 2.6.8-rc2-mm1 (root@phoebee) (gcc version 3.3.3 20040412
(Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)) #1 Wed Jul 28 11:39:48
CEST 2004
# gcc signal-bug.c -Wall -lpthread -lutil -o signal-bug; ./signal-bug
Died.
# cat /proc/version
Linux version 2.6.8 (pluto@vmx) (gcc version 3.4.2 20040806 (prerelease)
(PLD Linux)) #1 Sun Aug 15 19:58:30 CEST 2004
# rpm -q glibc
glibc-2.3.4-0.20040722.2+nptl
Signature · 3 lines
/* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */

                           #define say(x) lie(x)
#3 lore raw
In reply to Glyph Lefkowitz
Quoted 11 lines · Glyph Lefkowitz

Hello Kernel People,

Firstly, here is a brief example of some code that behaves very differently on 2.6.5 and 2.6.6:

http://www.twistedmatrix.com/users/glyph/signal-bug.c

I have verified that it says "Completed" on kernel 2.6.5, 2.6.3 and 2.6.1, and says "Died" on 2.6.6, 2.6.7 and 2.6.8.1, so I am pretty sure the difference is between 2.5.6 and 2.6.6.

FYI :

juhl@dragon:~$ gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
juhl@dragon:~$ cat /proc/version
Linux version 2.6.8.1 (juhl@dragon) (gcc version 3.4.1) #1 Sun Aug 15 22:01:56 CEST 2004

glibc is 2.3.2

--
Jesper Juhl <[email protected]>

#4 lore raw
Quoted 6 lines · Jesper Juhl
juhl@dragon:~$ gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
juhl@dragon:~$ cat /proc/version
Linux version 2.6.8.1 (juhl@dragon) (gcc version 3.4.1) #1 Sun Aug 15 22:01:56 CEST 2004

glibc is 2.3.2

Thanks for the feedback. I will test with 2.6.8.1 myself, just to be sure, but for those interested in the problem, I've included a few other recordings of results I got on hosts with a variety of architectures and kernel versions.

I could swear I tested this on a different host already, but I can't find the results, so I will build a 2.6.8.1 without debian patches, just to be sure.

glyph@trogdor:~% gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Died.
glyph@trogdor:~% cat /proc/version
Linux version 2.6.7-1-686 ([email protected]) (gcc version 3.3.4 (Debian 1:3.3.4-2)) #1 Thu Jul 8 05:36:53 EDT 2004 glyph@trogdor:~% dpkg -l libc6 | tail -1
ii libc6 2.3.2.ds1-16 GNU C Library: Shared libraries and Timezone

glyph@kazekage:~% gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Died.
glyph@kazekage:~% cat /proc/version
Linux version 2.6.7-1-k7 ([email protected]) (gcc version 3.3.4 (Debian 1:3.3.4-2)) #1 Thu Jul 8 06:45:35 EDT 2004 glyph@kazekage:~% dpkg -l libc6 | tail -1
ii libc6 2.3.2.ds1-16 GNU C Library: Shared libraries and Timezone

glyph@wolfwood:~$ gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
glyph@wolfwood:~$ cat /proc/version
Linux version 2.4.25vm-1um ([email protected]) (gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)) #2 Fri Feb 20 14:03:26 MST 2004
glyph@wolfwood:~$ dpkg -l libc6 | tail -1
ii  libc6          2.3.1-16       GNU C Library: Shared libraries and Timezone

glyph@pyramid:~% gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
glyph@pyramid:~% cat /proc/version
Linux version 2.4.18 ([email protected]) (gcc version 2.95.4 20011002 (Debian prerelease)) #1 SMP Wed Feb 25 14:26:24 MST 2004 glyph@pyramid:~% dpkg -l libc6 | tail -1
ii libc6 2.2.5-11.5 GNU C Library: Shared libraries and Timezone

glyph@watt:~$ gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
glyph@watt:~$ cat /proc/version
Linux version 2.4.25 (root@sparesolo20040319) (gcc version 2.95.4 20011002 (Debian prerelease)) #1 Wed Apr 7 16:22:47 MDT 2004
glyph@watt:~$ dpkg -l libc6 | tail -1
ii  libc6          2.3.2.ds1-12   GNU C Library: Shared libraries and Timezone
glyph@erlang:~$ gcc signal-bug.c -Wall -lutil -lpthread -o signal-bug; ./signal-bug
Completed.
glyph@erlang:~$ cat /proc/version
Linux version 2.6.4 (root@erlang) (gcc version 3.3.3 (Debian 20040320)) #10 Mon Mar 22 20:01:54 EST 2004
glyph@erlang:~$ dpkg -l libc6 | tail -1
ii  libc6          2.3.2.ds1-10   GNU C Library: Shared libraries and Timezone