-
Notifications
You must be signed in to change notification settings - Fork 18k
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/cgo: incorrectly handle SIGPIPE(and other signals) from non-Go thread #56150
Comments
The |
NOTICE that, the signal actually raised by socket write (as i said at begin). You can reproduced it with socket write broken pipe.I just want to find a equal form. With gdb i find socket broken pipe and kill SIGPIPE both trigger |
@ianlancetaylor I think it's better to reopen the issue. package main
/*
#include <pthread.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
void raiseSigpipe()
{
char fake_buf[1024];
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sa;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = htons(8989);
connect(sock, (struct sockaddr *)&sa, sizeof(sa));
send(sock, fake_buf, 1024, 0);
sleep(2);
send(sock, fake_buf, 1024, 0);
send(sock, fake_buf, 1024, 0); // sigpipe
}
void *subThread(void *_)
{
// raiseSigpipe();
return NULL;
}
void test()
{
pthread_t thread_id;
pthread_create(&thread_id, NULL, subThread, NULL);
pthread_join(thread_id, NULL);
raiseSigpipe();
}
*/
import "C"
import (
"net"
)
func main() {
go func() {
listener, _ := net.Listen("tcp", "127.0.0.1:8989")
for {
var d [1024]byte
conn, _ := listener.Accept()
conn.(*net.TCPConn).SetLinger(0)
conn.Read(d[:])
conn.Close()
}
}()
C.test()
// should not exit
println("run")
select {}
} |
My apologies, you're right: the code does check whether a |
Change https://go.dev/cl/442415 mentions this issue: |
Actually, signal hander defined in go can process the |
... And why not make program also ignore SIGPIPE from C thread as all signal processed by go signal hander ? |
We don't know what the C code is doing with If a Go program calls C code that doesn't want to get SIGPIPE, the C code install its own handler, perhaps |
Fixes golang#56150 Change-Id: Id990783562950ba8be7ce9526b7a811625f2190a Reviewed-on: https://go-review.googlesource.com/c/go/+/442415 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Following code is a minimal example. SIGPIPE raised from linux socket write, but can be reproduced by the following form.
According to the document, SIGPIPE should be caught by default, without affect program, just like the kill line in
test
function. But in sub-thread created by pthread, the SIGPIPE trigger the runtime.raisebadsignal, and make program exit, like kill line insubThread
function (uncomment it).What did you expect to see?
Go runtime catch the SIGPIPE from thread created by pthread, and everything works fine.
What did you see instead?
(uncomment kill function in
subThread
)kill in
subThread
make program exit, kill intest
make program continue running.The text was updated successfully, but these errors were encountered: