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

Not all os/error's handled in syscall.Errno.Is #37627

Closed
oncecreated opened this issue Mar 3, 2020 · 3 comments
Closed

Not all os/error's handled in syscall.Errno.Is #37627

oncecreated opened this issue Mar 3, 2020 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@oncecreated
Copy link

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

$ go version
go version go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes, there no changes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user1/.cache/go-build"
GOENV="/home/user1/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user1/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build325102545=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Recommendation from https://golang.org/src/syscall/syscall_unix.go?s=2815:2833#L115 , use errors.Is, while checking error from syscall. But some os.Err*, not handled in syscall.Errno.Is. In the example I try to check for os.ErrInvalid, and always get false. I think it's little obscure, all errors defined in os/errors.go need be check.

package main

import (
    "syscall"
    "net"
    "log"
    "errors"
    "os"
)

const TCP_FASTOPEN_CONNECT = 30

func main() {
    addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:1337")
    if err != nil {
        log.Fatal(err)
    }
    li, err := net.ListenTCP("tcp", addr)
    if err != nil {
        log.Fatal(err)
    }
    conn, err := li.SyscallConn()
    if err != nil {
        log.Fatal(err)
    }
    conn.Control(func(fd uintptr) {
        err = syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN_CONNECT, 5)
        if errors.Is(err, os.ErrInvalid) {
            log.Fatal("true ", err)
        } else {
            log.Fatal("false ", err) // false "invalid argument", the same as os.ErrInvalid
        }
    })
}

What did you expect to see?

Actual check with:

if errors.Is(err, os.ErrInvalid) {
}

What did you see instead?

Always false.

@bcmills
Copy link
Contributor

bcmills commented Mar 3, 2020

See also #30322.

@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2020

Based on the title of this issue, it seems the same as the one Bryan linked above.

Should we close this issue in favor of the existing one? Or should we make this issue more specific to a single case?

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 3, 2020
@oncecreated
Copy link
Author

Yeah, I think it's related.

@golang golang locked and limited conversation to collaborators Mar 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants