From b0b0d9828308368e9fbd59ec5de55801f568f720 Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Thu, 12 Nov 2020 21:19:52 -0800 Subject: runtime: linux iscgo support for not blocking nptl signals Under linux+cgo, OS threads are launched via pthread_create(). This abstraction, under linux, requires we avoid blocking signals 32,33 and 34 indefinitely because they are needed to reliably execute POSIX-semantics threading in glibc and/or musl. When blocking signals the go runtime generally re-enables them quickly. However, when a thread exits (under cgo, this is via a return from mstart()), we avoid a deadlock in C-code by not blocking these three signals. Fixes #42494 Change-Id: I02dfb2480a1f97d11679e0c4b132b51bddbe4c14 Reviewed-on: https://go-review.googlesource.com/c/go/+/269799 Reviewed-by: Ian Lance Taylor Reviewed-by: Austin Clements Trust: Tobias Klauser --- src/syscall/syscall_linux_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/syscall/syscall_linux_test.go') diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go index 153d0efef1..adeb7c9ebb 100644 --- a/src/syscall/syscall_linux_test.go +++ b/src/syscall/syscall_linux_test.go @@ -597,6 +597,14 @@ func compareStatus(filter, expect string) error { return nil } +// killAThread locks the goroutine to an OS thread and exits; this +// causes an OS thread to terminate. +func killAThread(c <-chan struct{}) { + runtime.LockOSThread() + <-c + return +} + // TestSetuidEtc performs tests on all of the wrapped system calls // that mirror to the 9 glibc syscalls with POSIX semantics. The test // here is considered authoritative and should compile and run @@ -647,6 +655,11 @@ func TestSetuidEtc(t *testing.T) { } for i, v := range vs { + // Generate some thread churn as we execute the tests. + c := make(chan struct{}) + go killAThread(c) + close(c) + if err := v.fn(); err != nil { t.Errorf("[%d] %q failed: %v", i, v.call, err) continue -- cgit v1.3-5-g9baa