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

x/sys/unix: unix.Connect cause uninterruptible sleep #52325

Closed
PumpkinSeed opened this issue Apr 13, 2022 · 1 comment
Closed

x/sys/unix: unix.Connect cause uninterruptible sleep #52325

PumpkinSeed opened this issue Apr 13, 2022 · 1 comment

Comments

@PumpkinSeed
Copy link

I didn't find related section where this package belongs, please ignore and close this if it's not relevant. Also if you can point me to the right direction.

What version of Go are you using (go version)?

go version go1.17.8 linux/amd64

Does this issue reproduce with the latest release?

Didn't try with 1.18

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/loow/.cache/go-build"
GOENV="/home/loow/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/loow/development/go/pkg/mod"
GOOS="linux"
GOPATH="/home/loow/development/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.8"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build52921490=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"strconv"
	"strings"
	"syscall"

	"golang.org/x/sys/unix"
)

func main() {
	var addr = "54:88:2D:EE:EE:EE"
	fd, err := unix.Socket(syscall.AF_BLUETOOTH, syscall.SOCK_STREAM, unix.BTPROTO_RFCOMM)
	if err != nil {
		panic(err)
	}
	socketAddr := &unix.SockaddrRFCOMM{Addr: str2ba(addr), Channel: 6}
	if err := unix.Connect(fd, socketAddr); err != nil {
		panic(err)
	}
}

// str2ba converts MAC address string representation to little-endian byte array
func str2ba(addr string) [6]byte {
	a := strings.Split(addr, ":")
	var b [6]byte
	for i, tmp := range a {
		u, _ := strconv.ParseUint(tmp, 16, 8)
		b[len(b)-1-i] = byte(u)
	}
	return b
}

What did you expect to see?

It would be nice if I get an error if the particular device isn't available.

What did you see instead?

I got an uninterruptible sleep in case of the device determined in the address isn't available.

$ px aux | grep go-build85
XXX       35538  0.0  0.0 703112  1676 pts/2    D    10:59   0:00 /tmp/go-build851823850/b001/exe/main

$ sudo kill -9 35538

$ px aux | grep go-build85
XXX       35538  0.0  0.0 703112  1676 pts/2    D    10:59   0:00 /tmp/go-build851823850/b001/exe/main
@ianlancetaylor ianlancetaylor changed the title golang.org/x/sys/unix: unix.Connect cause uninterruptible sleep x/sys/unix: unix.Connect cause uninterruptible sleep Apr 14, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 14, 2022
@ianlancetaylor
Copy link
Contributor

All the Go code is doing is making the system call. If the process locks up and becomes immune to SIGKILL, that sounds like a kernel bug. There is nothing that Go can do to become immune to SIGKILL.

I imagine that the same thing would happen for an equivalent C program.

I'm going to close this because I don't think there is anything we can change in Go to affect this. Please comment if you disagree.

@golang golang locked and limited conversation to collaborators Apr 14, 2023
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

3 participants