Dear Maintainer,
In the example below, glibc 2.34 from experimental causes a spurious
EINTR error in the poll() call from the child thread. It seems that
thread cancellation causes the poll() to be spuriously interrupted,
even though the cancellation is explicitly disabled at that time.
As far as I understand, POSIX allows (or even requires) thread
cancellation to be essentially like a signal interruption, save for
ending the thread. But that is *only* from the moment that cancellation
is effected. Cancellation cannot be effected while it is disabled by
definition, so the behaviour from glibc seems wrong here.
This regression is known to break the test suite from the VLC package.
Rolling back to 2.33 from unstable solves the problem.
----8<----
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <poll.h>
#include <pthread.h>
static void *thread(void *data)
{
int canc;
(void) data;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &canc);
if (poll(NULL, 0, 2000) < 0) {
perror("Unexpected poll error");
abort();
}
pthread_setcancelstate(canc, NULL);
return NULL;
}
int main(void)
{
pthread_t th;
void *ret;
struct timespec ts = { 0, 100*1000*1000 };
if (pthread_create(&th, NULL, thread, NULL)) {
perror("pthread_create");
return 1;
}
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
pthread_cancel(th);
pthread_join(th, &ret);
assert(ret == NULL);
return 0;
}
---->8----
Hi, Thanks for the example, it's very useful to reproduce and understand the issue. poll() is a cancellation point. It appears to me that POSIX actually allows this behaviour for cancellation points: "The side effects of acting upon a cancellation request while suspended during a call of a function are the same as the side effects that may be seen in a single-threaded program when a call to a function is interrupted by a signal and the given function returns [EINTR]. Any such side effects occur before any cancellation cleanup handlers are called." https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html https://sourceware.org/git/?p=glibc.git;a=commit;h=26cfbb7162ad364d53d69f6d482f2d87b5950524 Regards, Aurelien
Hi, Le lauantaina 26. maaliskuuta 2022, 21.34.38 EET Aurelien Jarno a écrit : I don't think so... AFAIU, in POSIX, "acting upon" a cancellation request means to move the cancellation request past the pending state, in other words, actually cancel the thread. That quote clarifies that the signal-like interruption is observed in the cancelled thread flow of execution before the cancellation clean-up handlers. Otherwise the next paragraph would not make much sense, particularly the last sentence: And it would get even more nonsensical / contradictory in the following section: This paragraph clarifies that cancellation cannot occur recursively / more than once per thread. Assuming that "acting upon a cancellation request" would be permissible with cancellation disabled, this sentence would imply that cancellation is disabled permanently, and the thread will never get cancelled at all.
We believe that the bug you reported is fixed in the latest version of
glibc, which is due to be installed in the Debian FTP archive.
A summary of the changes between this version and the previous one is
attached.
Thank you for reporting the bug, which will now be closed. If you
have further comments please address them to 1008174@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.
Debian distribution maintenance software
pp.
Aurelien Jarno <aurel32@debian.org> (supplier of updated glibc package)
(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Sat, 16 Apr 2022 13:10:56 +0200
Source: glibc
Architecture: source
Version: 2.34-0experimental4
Distribution: experimental
Urgency: medium
Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>
Changed-By: Aurelien Jarno <aurel32@debian.org>
Closes: 1006692 1008174
Changes:
glibc (2.34-0experimental4) experimental; urgency=medium
.
[ Aurelien Jarno ]
* debian/patches/git-updates.diff: update from upstream stable branch:
- Fixes spurious EINTR when thread cancellation is disabled. Closes:
#1008174.
- debian/patches/any/local-revert-bz13979.diff: refresh.
.
[ Johannes Schauer Marin Rodrigues ]
* debian/debhelper.in/libc.postinst: do not re-exec init if DPKG_ROOT is
set. Closes: #1006692.
Checksums-Sha1:
b73691aec90b98d88c254e8a4fda81eb14adce9e 9683 glibc_2.34-0experimental4.dsc
88b90828dd1fcbf896518bdd08b78860ec32cb2c 895432 glibc_2.34-0experimental4.debian.tar.xz
fa5819e2454f0c27b79c88b7663c5502777bfc29 9462 glibc_2.34-0experimental4_source.buildinfo
Checksums-Sha256:
75e500abab82ae3da23ed3a7a96fb6e4d4fc73a644a1bfb2baf2886aa0cee432 9683 glibc_2.34-0experimental4.dsc
6c3388850a5bbf01ffc56347f876ce706f60b7b98fbf7c16db1ee45e5c4a0983 895432 glibc_2.34-0experimental4.debian.tar.xz
197b193d0573cf4667c24d11459d673a51b45bceac2ece6840d2eeb942d487e4 9462 glibc_2.34-0experimental4_source.buildinfo
Files:
a4de258baab6a3d856cb8bcead38b187 9683 libs required glibc_2.34-0experimental4.dsc
d56abfaf2ff0bccb673ada497654551f 895432 libs required glibc_2.34-0experimental4.debian.tar.xz
01b0c283bdbf713e4776032e54d721fe 9462 libs required glibc_2.34-0experimental4_source.buildinfo
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCgAdFiEEUryGlb40+QrX1Ay4E4jA+JnoM2sFAmJapNYACgkQE4jA+Jno
M2u4dg//ZVQG/5XpFTJP6zX5cr5E4PwQKxGM7cZSfpBkHQkeWRZoem7fKbQQ8WmH
3N5CkYt6r9hlvP6Cdw4FJH/o1WnUjSM3GihorXVLSMsXWPHEQM1Ov00kwXHRPOj0
ewA8I/aSFvyG/i8Hh8+6uqST8thdcYtUXIM6yIskXpHSjW88d4gK8yaxKqvFSQXG
nOzhdRsRnLGILRMprtWacnwY2WV3M9O0vWZftccT485cjj+XPH2rGsEwGgC0j4wN
Hh9N1znxMtZuGm7dfpdIosXyqvb172gyC71LlbynICR2gAGtPTvvWvrjRDIUuEYr
rjBxcgNVhVPFxkW7giw0/GIYNkc9wAr0QwGSvhQYPLnoPPNOcfdM7oXX9Ali7KV2
2iSJJzf2JAEkGOiIcQqxau4yLj3K8ApmX8t0lSODcIDTxfZZsLXPKcv9JYqePU4U
NcJvykhUItQVO5oU6VqIHfI1nrVF4W/CU+hvatcMhYcmp5iYC6fHPeOyPhQmDTTf
nKbG2U38EqL1dmexXRc/Es2Yf9C0lPDdD0jGE4pTJxawpHyvi70KOzsSinzcZTc8
blL9ZAdjAGEE45j7k06xq6gHcFaIaOr+UQ83i8XbhmbU68Gk7KFuSpbjllvST02J
AtBF9+fRPkg06uTuWFmnaOerIHxWWYDt5TbTkqmbgmqVUbsP8XY=
=/V2+
-----END PGP SIGNATURE-----