Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: deadlock due to blocked glibc-internal signals #12498

Closed
hlandau opened this issue Sep 4, 2015 · 6 comments
Closed

runtime: deadlock due to blocked glibc-internal signals #12498

hlandau opened this issue Sep 4, 2015 · 6 comments

Comments

@hlandau
Copy link

hlandau commented Sep 4, 2015

The following code demonstrates the bug. The expected behaviour is that the program exits. Instead, the program hangs forever.

I did not experience these issues with Go 1.4; I suspect it is a result of the changes introduced in #9400, involving SIGSETXID.

go version go1.5 linux/amd64
Linux andover 4.1.2-2-ARCH #1 SMP PREEMPT Wed Jul 15 08:30:32 UTC 2015 x86_64 GNU/Linux
  • The deadlock occurs regardless of whether you run the program as root, as setxid is attempted on all threads even if they all ultimately fail.
  • Tested to occur with at least GOMAXPROCS=1 and GOMAXPROCS=8.
package main

import (
    "fmt"
    "os"
    "os/signal"
    "syscall"
)

/*
#define _GNU_SOURCE
#include <unistd.h>
*/
import "C"

func main() {
    signal.Notify(make(chan os.Signal, 10), syscall.SIGINT)
    fmt.Printf("rv: %v\n", C.setresgid(99, 99, 99))
}
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 4, 2015
@gopherbot
Copy link

CL https://golang.org/cl/14297 mentions this issue.

@hlandau
Copy link
Author

hlandau commented Sep 5, 2015

FYI, this is causing some quite serious issues. The Go1.5.1 milestone is maybe more appropriate?

@ianlancetaylor ianlancetaylor modified the milestones: Go1.5.2, Go1.6 Sep 8, 2015
@rsc rsc changed the title Deadlock when calling C.setuid/setgid after signal.Notify (go1.5) runtime: deadlock due to blocked glibc-internal signals Nov 13, 2015
@gopherbot
Copy link

CL https://golang.org/cl/16967 mentions this issue.

ianlancetaylor added a commit that referenced this issue Nov 17, 2015
… thread

Glibc uses some special signals for special thread operations.  These
signals will be used in programs that use cgo and invoke certain glibc
functions, such as setgid.  In order for this to work, these signals
need to not be masked by any thread.  Before this change, they were
being masked by programs that used os/signal.Notify, because it
carefully masks all non-thread-specific signals in all threads so that a
dedicated thread will collect and report those signals (see ensureSigM
in signal1_unix.go).

This change adds the two glibc special signals to the set of signals
that are unmasked in each thread.

Fixes #12498.

Change-Id: I797d71a099a2169c186f024185d44a2e1972d4ad
Reviewed-on: https://go-review.googlesource.com/14297
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-on: https://go-review.googlesource.com/16967
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@rsc
Copy link
Contributor

rsc commented Nov 24, 2015

A report from golang-dev says this still happens in go test -race mode:

From: Mark Pulford mark@kyne.com.au
Date: Mon, Nov 23, 2015 at 7:21 PM
Subject: [golang-dev] Re: almost Go 1.5.2 in release-branch.go1.5
To: golang-dev golang-dev@googlegroups.com

I've just noticed that the Setgid test updated in rev a897684 fails under the race detector. The previous rev builds and tests cleanly.

$ set | grep ^GO
GO15VENDOREXPERIMENT=
GOARCH=amd64
GOBIN=
GOEXE=
GOGCCFLAGS='-fPIC -m64 -pthread -fmessage-length=0'
GOHOSTARCH=amd64
GOHOSTOS=linux
GOOS=linux
GORACE=
GOROOT=/home/mark/go
GOTOOLDIR=/home/mark/go/pkg/tool/linux_amd64
$ which go
~/go/bin/go

$ go test -run Setgid
PASS
ok      _/home/mark/go/misc/cgo/test    0.002s

$ go test -race -run Setgid
--- FAIL: TestSetgid (5.00s)
    setgid_linux.go:47: setgid hung after signal.Notify
FAIL
exit status 1
FAIL    _/home/mark/go/misc/cgo/test    5.007s

I haven't investigated further.

@rsc rsc reopened this Nov 24, 2015
@ianlancetaylor
Copy link
Contributor

I can not recreate the problem using -race.

@rsc
Copy link
Contributor

rsc commented Nov 25, 2015

Mark reports that he was running stale binaries.

@rsc rsc closed this as completed Nov 25, 2015
@golang golang locked and limited conversation to collaborators Nov 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants