public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/29214] New: pthread_setcanceltype fails to set type
@ 2022-05-31 17:19 robin at gareus dot org
  2022-05-31 18:45 ` [Bug nptl/29214] " adhemerval.zanella at linaro dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: robin at gareus dot org @ 2022-05-31 17:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

            Bug ID: 29214
           Summary: pthread_setcanceltype fails to set type
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: robin at gareus dot org
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 14127
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14127&action=edit
example code to reproduce the bug

With glibc-2.35-69-g28ea43f8d6 (as currently shipped by archlinux and openSuSE)
it is no longer possible to change the pthread cancel type to
`PTHREAD_CANCEL_ASYNCHRONOUS'.

This leads to applications that rely on async cancellation to never terminate
[1].

The problem was introduced by commit ba9c42ac0e265bf1e4ec1075fa20e7166fda8bfc,
and reverting that fixes the issue [2].

Attached is a small test-tool to reproduce the bug.

--

[1] https://discourse.ardour.org/t/ardour-hanging-at-shutdown/107260 in this
case JACK waits on a futex, just like the test-tool.

[2] The problem seems to be specific to the change in `pthread_setcanceltype',
not the overall commit.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
@ 2022-05-31 18:45 ` adhemerval.zanella at linaro dot org
  2022-05-31 18:56 ` adhemerval.zanella at linaro dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2022-05-31 18:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |adhemerval.zanella at linaro dot o
                   |                            |rg
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2022-05-31
     Ever confirmed|0                           |1
                 CC|                            |adhemerval.zanella at linaro dot o
                   |                            |rg
            Version|unspecified                 |2.35

--- Comment #1 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
It affects master as well, I will take a look.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
  2022-05-31 18:45 ` [Bug nptl/29214] " adhemerval.zanella at linaro dot org
@ 2022-05-31 18:56 ` adhemerval.zanella at linaro dot org
  2022-05-31 19:12 ` robin at gareus dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2022-05-31 18:56 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

--- Comment #2 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
The problem seems not to be on pthread_setcanceltype, but rather on
nptl/libc-clenaup.c that implements handlers used by printf.  If you remove the
printf on the thread function the thread is cancelled as expected. Could you
check if the following patch fixes it?

diff --git a/nptl/libc-cleanup.c b/nptl/libc-cleanup.c
index c4a83591bf..2ce59388d4 100644
--- a/nptl/libc-cleanup.c
+++ b/nptl/libc-cleanup.c
@@ -57,7 +57,8 @@ __libc_cleanup_pop_restore (struct _pthread_cleanup_buffer
*buffer)
   THREAD_SETMEM (self, cleanup, buffer->__prev);

   int cancelhandling = atomic_load_relaxed (&self->cancelhandling);
-  if (cancelhandling & CANCELTYPE_BITMASK)
+  if (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED
+      && (cancelhandling & CANCELTYPE_BITMASK) == 0)
     {
       int newval;
       do


I will send a patch along with a testcase.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
  2022-05-31 18:45 ` [Bug nptl/29214] " adhemerval.zanella at linaro dot org
  2022-05-31 18:56 ` adhemerval.zanella at linaro dot org
@ 2022-05-31 19:12 ` robin at gareus dot org
  2022-05-31 19:16 ` adhemerval.zanella at linaro dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: robin at gareus dot org @ 2022-05-31 19:12 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

--- Comment #3 from Robin Gareus <robin at gareus dot org> ---
Yes, that patch fixes the issue. Confirmed with both the test-tool, as well as
the "real world" issue with jackd + Ardour!

Thanks for the amazingly fast response and fix!

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
                   ` (2 preceding siblings ...)
  2022-05-31 19:12 ` robin at gareus dot org
@ 2022-05-31 19:16 ` adhemerval.zanella at linaro dot org
  2022-06-01  1:41 ` robin at gareus dot org
  2022-06-08 12:36 ` adhemerval.zanella at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2022-05-31 19:16 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

--- Comment #4 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
(In reply to Robin Gareus from comment #3)
> Yes, that patch fixes the issue. Confirmed with both the test-tool, as well
> as the "real world" issue with jackd + Ardour!
> 
> Thanks for the amazingly fast response and fix!

Well, I was the one that actually messed up the revert ;)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
                   ` (3 preceding siblings ...)
  2022-05-31 19:16 ` adhemerval.zanella at linaro dot org
@ 2022-06-01  1:41 ` robin at gareus dot org
  2022-06-08 12:36 ` adhemerval.zanella at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: robin at gareus dot org @ 2022-06-01  1:41 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

--- Comment #5 from Robin Gareus <robin at gareus dot org> ---
> The problem seems not to be on pthread_setcanceltype, but rather on nptl/libc-clenaup.c that implements handlers used by printf.

The issue is also present with a direct call, without printf() or checking the
return value.

Regardless, the patch fixes this as well.


> Well, I was the one that actually messed up the revert ;)

No shame in that, it happens to the best.
404656009b459658138ed1bd18f3c6cf3863e6a6 is a large complex commit as well.

It's really distros who are to blame for shipping somewhat random git non
tagged git revision. Then again arch users asked for it :)

debian/sid, ubuntu use 2.35 tagged release and are not affected.

Keep up the good work!

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug nptl/29214] pthread_setcanceltype fails to set type
  2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
                   ` (4 preceding siblings ...)
  2022-06-01  1:41 ` robin at gareus dot org
@ 2022-06-08 12:36 ` adhemerval.zanella at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2022-06-08 12:36 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29214

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |2.36

--- Comment #6 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
Fixed on 2.36.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-08 12:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 17:19 [Bug nptl/29214] New: pthread_setcanceltype fails to set type robin at gareus dot org
2022-05-31 18:45 ` [Bug nptl/29214] " adhemerval.zanella at linaro dot org
2022-05-31 18:56 ` adhemerval.zanella at linaro dot org
2022-05-31 19:12 ` robin at gareus dot org
2022-05-31 19:16 ` adhemerval.zanella at linaro dot org
2022-06-01  1:41 ` robin at gareus dot org
2022-06-08 12:36 ` adhemerval.zanella at linaro dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).