Skip to content

runtime: crash when receiving multiple signals on C threads on NetBSD #5885

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

Closed
minux opened this issue Jul 14, 2013 · 14 comments
Closed

runtime: crash when receiving multiple signals on C threads on NetBSD #5885

minux opened this issue Jul 14, 2013 · 14 comments

Comments

@minux
Copy link
Member

minux commented Jul 14, 2013

run the following program on netbsd/386:
package main

/*
#include <signal.h>
#include <pthread.h>

static void *thread(void *p) {
    (void)p;
    const int N = 100;
    int i;
    for (i = 0; i < N; i++)
        pthread_kill(pthread_self(), SIGCHLD);
    return NULL;
}
void testSendSIG() {
    const int M = 10;
    pthread_t tid[M];
    int i;
    for (i = 0; i < M; i++)
        pthread_create(&tid[i], 0, thread, NULL);
    for (i = 0; i < M; i++)
        pthread_join(tid[i], 0);
}
*/
import "C"

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

func main() {
    ch, wait := make(chan os.Signal), make(chan bool)
    signal.Notify(ch, syscall.SIGCHLD)
    go func() {
        wait2 := wait
        for {
            select {
            case v := <-ch:
                fmt.Println("got", v)
                wait <- false
            case <-wait2:
                wait2 = nil
            }
        }
    }()
    wait <- true
    C.testSendSIG()
    <-wait
}


it will crash as follows:
SIGSEGV: segmentation violation
PC=0x3e8


goroutine 1 [syscall]:
main._Cfunc_testSendSIG(0x80b0ca0)
    command-line-arguments/_obj/_cgo_defun.c:43 +0x31
main.main()
    command-line-arguments/_obj/signal.cgo1.go:34 +0x14c

goroutine 3 [syscall]:
os/signal.loop()
    /home/builder/go.hg/src/pkg/os/signal/signal_unix.go:21 +0x1e
created by os/signal.init·1
    /home/builder/go.hg/src/pkg/os/signal/signal_unix.go:27 +0x31

goroutine 4 [select]:
main.func·001()
    command-line-arguments/_obj/signal.cgo1.go:23 +0x15c
created by main.main
    command-line-arguments/_obj/signal.cgo1.go:31 +0x12a

goroutine 5 [runnable]:
runtime.exitsyscall()
    /home/builder/go.hg/src/pkg/runtime/proc.c:1466 +0x109
runtime.cgocallbackg(0x18438c2c, 0x18438c3c, 0x4)
    /home/builder/go.hg/src/pkg/runtime/cgocall.c:244 +0x76
runtime.cgocallback_gofunc(0x0, 0x0)
    /home/builder/go.hg/src/pkg/runtime/asm_386.s:583 +0x5a
runtime.goexit()
    /home/builder/go.hg/src/pkg/runtime/proc.c:1289

eax     0x0
ebx     0x18439250
ecx     0x1
edx     0x0
edi     0x805c540
esi     0x18401780
ebp     0x813b160
esp     0x18438bd8
eip     0x3e8
eflags  0x10216
cs      0x1b
fs      0xab
gs      0xb3
@minux
Copy link
Member Author

minux commented Jul 14, 2013

Comment 1:

i have reduced N to 1, and M to 2.
it seems we should be able to reproduce the problem even using export from multiple
C thread simultaneously.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 2:

Labels changed: added go1.2.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 3:

I can't reproduce this on Darwin/386. When I run the program it just says 'got child
exited' and then exits.
Are the pthread_creates all succeeding? Perhaps if one fails and leaves tid[i]
uninitialized, the later pthread_join will dereference a bad value.

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 4:

Also can you run it under gdb and see if you can get a stack trace for the C code that
is dying?

@rsc
Copy link
Contributor

rsc commented Sep 11, 2013

Comment 5:

It also works on linux/386. Starting to look like a NetBSD problem.

Labels changed: added go1.2maybe, removed go1.2.

@rsc
Copy link
Contributor

rsc commented Oct 2, 2013

Comment 6:

Labels changed: added go1.3, removed go1.2maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 8:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 9:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented Apr 3, 2014

Comment 10:

It would be nice if someone found this but NetBSD is not one of the first class ports
(golang.org/wiki/PortingPolicy), so I am removing the release tag entirely. Adding
OS-NetBSD. If NetBSD is ever to become a first-class port, hopefully we'll notice this
issue and force someone to fix the bug then.

Labels changed: added os-netbsd, removed release-go1.3.

@rsc
Copy link
Contributor

rsc commented May 21, 2014

Comment 11:

Labels changed: added priority-later, release-none, removed priority-soon.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@mikioh
Copy link
Contributor

mikioh commented Jan 22, 2016

Note that this still crashes w/ go1.6beta1 + the fix for #14067 on both netbsd/386 and netbsd/amd64.

@mikioh mikioh changed the title runtime: crash when receiving multiple signals on C threads on NetBSD/386 runtime: crash when receiving multiple signals on C threads on NetBSD Jan 26, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Jul 7, 2017

All NetBSD bugs are on hold until there's a release later than NetBSD 7.1, which still had known issues fixed in NetBSD-current after 7.1.

@bradfitz
Copy link
Contributor

Fixed by requiring NetBSD 8+ for Go 1.10.

Documentation bug is #22911

@golang golang locked and limited conversation to collaborators Nov 28, 2018
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

5 participants