]> git.ipfire.org Git - thirdparty/man-pages.git/commit
close.2: Note behavior when close() happens in a parallel thread
authorMichael Kerrisk <mtk.manpages@gmail.com>
Fri, 8 May 2020 15:44:01 +0000 (17:44 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Sat, 9 May 2020 11:24:39 +0000 (13:24 +0200)
commitc2f15a1349a7271f6c1d81361ec8b256266e1c09
tree608faf954cc257ff54ea09a9ff0a89f0739359eb
parent3862672084d94d7de222c69857dcb23b8c7f7dda
close.2: Note behavior when close() happens in a parallel thread

If one thread is blocked in an I/O system call on a file descriptor
that is closed in another thread, then the blocking system call
does not return immediately, but rather when the I/O operation
completes. This surprises some people, but is longstanding
behavior.

See https://bugzilla.kernel.org/show_bug.cgi?id=53781

and

https://lore.kernel.org/lkml/3B1E3D86.C7A7874@canal-plus.fr/
To: linux-kernel@vger.kernel.org
Subject: PROBLEM: I/O system call never returns if file desc is closed in the  meantime
Date: Wed, 06 Jun 2001 16:26:14 +0200

Examples where people are surprised by this behavior:
https://www.linuxquestions.org/questions/linux-networking-3/recv-is-not-coming-out-of-blocking-after-closing-the-socket-459461/
https://stackoverflow.com/questions/3589723/can-a-socket-be-closed-from-another-thread-when-a-send-recv-on-the-same-socket

Reported-by: Thierry Lelegard <thierry.lelegard@canal-plus.fr>
Reported-by: Lukas Czerner <lczerner@redhat.com>
Reported-by: Peter Schiffer <pschiffe@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man2/close.2