Skip to content

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

@PumpkinSeed

Description

@PumpkinSeed

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions