From nobody Tue Dec 03 16:17:52 2024 X-Original-To: threads@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y2m5r5Cd8z5gLdg for ; Tue, 03 Dec 2024 16:17:52 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y2m5r0dGyz4KnS for ; Tue, 3 Dec 2024 16:17:52 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733242672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y5wgDFyYqv9Va4WYYix5kmjAUeglG8umzKhrJQHIWI0=; b=RweXtVfiWz1HGV+V7mbVldzd3EMfqOsdio7rekr1AqG+l+Y+AVCdRDczq4Kv3eDX9gObQ5 nITzQGrEu4Lw6p/3ioTaag8r3lOMBd3xF6KLuDnXr8LQ7o5kcmMhCRPVGtMV943OJsFiOL 0o+f1bi8AwRYCFHidwLwJe5YX2l4a2lVWoVt+2U1VVRcxrd7tdiG8eKy0LoyQjVzQbO4Lo cV+RUug1DWQO3+XqVm7UJozEHT1tgjWR/p/i68NY89SxtWrTANGr0DwNc7oFhOVnBllvNd Tvwuyix1xua/+UQy7FBzz8skFaXFMhjA/WpnXfSgPzo3C7lhNil7CFGxlvzHGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733242672; a=rsa-sha256; cv=none; b=eCe8cscACvYEhU10zFyJOTxHHIVDMHtSsgyunqyhKkvKkP/Faf+8qnYUziViuGPQKB2KyM fUMYqxCZGkHdi5u+LHCq2Exg1r2dCrzR2aSFrWuprouyAIYLC3dMs3MYgbvy1YYcKBqyfZ XbITpO6W0sNF3muBnNG3oYw3dl5Ikor+w1Ime+uc3wDu07SXl7LkMO50jL1Rnox3p6ax8H Y0d+b5c8ouThWE5HDnZEfMz+Oxf633Rv1J9oOMnykK5mfUtakyYfyXxPPH1IFoBp37kn1i YOKg++jJoi6xWG6npy/hfj1R6/nHT7GzmQJ/5kjaapLyo1KWhUfIKozs2q0KRA== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y2m5r06PfzVmw for ; Tue, 3 Dec 2024 16:17:52 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 4B3GHp1K027960 for ; Tue, 3 Dec 2024 16:17:51 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 4B3GHpJH027959 for threads@FreeBSD.org; Tue, 3 Dec 2024 16:17:51 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: threads@FreeBSD.org Subject: [Bug 283101] pthread_cancel() doesn't cancel a thread that's currently in pause() Date: Tue, 03 Dec 2024 16:17:52 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: 13.3-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: nabijaczleweli@nabijaczleweli.xyz X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: threads@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Threading List-Archive: https://lists.freebsd.org/archives/freebsd-threads List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-threads@freebsd.org Sender: owner-freebsd-threads@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D283101 Bug ID: 283101 Summary: pthread_cancel() doesn't cancel a thread that's currently in pause() Product: Base System Version: 13.3-RELEASE Hardware: amd64 OS: Any Status: New Severity: Affects Some People Priority: --- Component: threads Assignee: threads@FreeBSD.org Reporter: nabijaczleweli@nabijaczleweli.xyz Downstream bug: https://github.com/openzfs/zfs/issues/16731 On FreeBSD, zfs send sometimes hangs in a deadlock after pthread_cancel(tid= ); pthread_join(tid, NULL); while the thread is in pause(). The program looks something like this: #include #include #include #include #include static void send_progress_thread_act(int sig, siginfo_t *info, void *uconte= xt) {} static void timer_delete_cleanup(void *timer) {} void *send_progress_thread(void *arg1) { const struct sigaction signal_action =3D {.sa_sigaction =3D send_progress_thread_act, .sa_flags =3D SA_SIGINFO= }; sigaction(SIGUSR1, &signal_action, NULL); pthread_cleanup_push(timer_delete_cleanup, NULL); for(;;) { pause(); // <- thread blocked here // zfs_send_progress(), time(), localtime_r(), setproctitle(), fprintf() fprintf(stderr, "unpaused\n"); } pthread_cleanup_pop(true); return NULL; } int main() { pthread_t tid; pthread_create(&tid, NULL, send_progress_thread, NULL); sigset_t new; sigemptyset(&new); sigaddset(&new, SIGUSR1); pthread_sigmask(SIG_BLOCK, &new, NULL); sleep(1); // some sort of work pthread_cancel(tid); pthread_join(tid, NULL); // <- thread blocked here } (In reality there's also a timer that may send SIGUSR1s and SIGINFO is also consumed but this is largely irrelevant.) The backtrace looks like this: Thread 2 (LWP 259843 of process 95307): #0 0x000000082872c6aa in _sigsuspend () from /lib/libc.so.7 #1 0x0000000825f47fb6 in ?? () from /lib/libthr.so.3 #2 0x00000008286a2a65 in pause () from /lib/libc.so.7 #3 0x0000000820e3d7d5 in send_progress_thread (arg=3D0x8208cf2c0) at lib/libzfs/libzfs_sendrecv.c:1018 #4 0x0000000825f3eb05 in ?? () from /lib/libthr.so.3 #5 0x0000000000000000 in ?? () Backtrace stopped: Cannot access memory at address 0x82ce7a000 Thread 1 (LWP 100403 of process 95307): #0 0x0000000825f3be2c in ?? () from /lib/libthr.so.3 #1 0x0000000825f40a2e in ?? () from /lib/libthr.so.3 #2 0x0000000820e3da4f in send_progress_thread_exit (hdl=3D0x349d6143c000, ptid=3D0x349d61412700, oldmask=3Doldmask@entry=3D0x8208cf1b0) at lib/libzfs/libzfs_sendrecv.c:1074 #3 0x0000000820e40367 in dump_snapshot (zhp=3D0x349d6145a500, arg=3Darg@entry=3D0x8208d0ec8) at lib/libzfs/libzfs_sendrecv.c:1291 #4 0x0000000820e3014a in zfs_iter_snapshots_sorted_v2 (zhp=3Dzhp@entry=3D0x349d6145a000, flags=3Dflags@entry=3D0, callback=3D0x82= 0e3ff30 , data=3Ddata@entry=3D0x8208d0ec8, min_txg=3D8889024, max_tx= g=3D8890857) at lib/libzfs/libzfs_iter.c:352 #5 0x0000000820e3fd34 in dump_filesystem (zhp=3D0x349d6145a000, sdd=3D0x82= 08d0ec8) at lib/libzfs/libzfs_sendrecv.c:1364 #6 0x0000000820e3ec99 in dump_filesystems (rzhp=3D0x349d61412700, rzhp@entry=3D0x349d6145a000, sdd=3D0x2, sdd@entry=3D0x8208d0ec8) at lib/libzfs/libzfs_sendrecv.c:1432 #7 0x0000000820e3e413 in zfs_send_cb_impl (zhp=3D0x349d6145a000, fromsnap=3D, tosnap=3D0x349d61419106 "zpair-02749186397145403432-cartman-674eaa54-537c2abe", flags=3D0x8208d16f0, outfd=3D1, filter_func=3D0x0, cb_arg=3D0x8208d16d0, debugnvp=3D0x0) at lib/libzfs/libzfs_sendrecv.c:2506 #8 0x0000000820e3c26e in zfs_send_cb (outfd=3D0, arg=3D) at lib/libzfs/libzfs_sendrecv.c:2559 #9 0x0000000820e3c237 in zfs_send (zhp=3Dzhp@entry=3D0x349d6145a000, fromsnap=3Dfromsnap@entry=3D0x349d614190c0 "zpair-02749186397145403432-cartman-674e8e34-16208f9f", tosnap=3Dtosnap@entry=3D0x349d61419106 "zpair-02749186397145403432-cartman-674eaa54-537c2abe", flags=3D0x0, flags@entry=3D0x8208d16f0, outfd=3D0, outfd@entry=3D1, filter_func=3D0x0, cb_arg=3D0x8208d16d0, debugnvp=3D0x0) at lib/libzfs/libzfs_sendrecv.c:2577 #10 0x0000000000215754 in zfs_do_send (argc=3D, argv=3D) at cmd/zfs/zfs_main.c:5099 #11 0x000000000020fd18 in main (argc=3D6, argv=3D0x8208d1850) at cmd/zfs/zfs_main.c:9249 This is obviously wrong, since the thread is /sleeping in a cancellation point/.=20 Adding pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); to the top= of the thread doesn't change anything. In this case, it's obviously wrong beca= use pthread_cancel()... didn't cancel the thread. --=20 You are receiving this mail because: You are the assignee for the bug.=