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

os: EINTR on Darwin when reading from os.Stdin #22838

Closed
tibbes opened this issue Nov 21, 2017 · 4 comments
Closed

os: EINTR on Darwin when reading from os.Stdin #22838

tibbes opened this issue Nov 21, 2017 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tibbes
Copy link
Contributor

tibbes commented Nov 21, 2017

What did you do?

I built this program on a Mac, and also cross-compiled it using GOOS=linux, then ran it on both platforms to see what happened when I hit Ctrl-Z and resumed the program using fg 1.

package main

import (
        "bufio"
        "fmt"
        "os"
)

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        for scanner.Scan() {
        }
        fmt.Println(scanner.Err())
}

What did you see on Linux?

$ ./tmp
^Z
[1]+  Stopped                 ./tmp
$ fg 1
./tmp

What did you see on Darwin (macOS)?

$ ./tmp
^Z
[1]+  Stopped                 ./tmp
$ fg 1
./tmp
read /dev/stdin: interrupted system call
$

What would you expect?

I would expect the behaviour to be the same on both platforms. A search of other issues indicated that the following may be relevant:

System details

go version go1.9.2 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/julian/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/x1/vfmlq7554nx8t6hzhl8804p40000gn/T/go-build975276148=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9.2 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.2
uname -v: Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.1
BuildVersion:	17B48
lldb --version: lldb-900.0.57
  Swift-4.0
@bradfitz bradfitz changed the title EINTR on Darwin when reading from os.Stdin os: EINTR on Darwin when reading from os.Stdin Nov 21, 2017
@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 21, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Nov 21, 2017
@bradfitz
Copy link
Contributor

I can reproduce on Go tip (after Go 1.9) and on a macOS version one before yours:

brad5k:~ $ ./in 
^Z
[1]+  Stopped                 ./in
brad5k:~ $ fg
./in
read /dev/stdin: interrupted system call
brad5k:~ $ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G1036

@ianlancetaylor
Copy link
Contributor

That is rather annoying. We don't install a SIGTSTP signal, nor should we. So we just take the default action. It looks like on GNU/Linux the default action is to not interrupt a read, but on MacOS it is.

@ianlancetaylor
Copy link
Contributor

The fix took 10 seconds, the test case took five hours.

@gopherbot
Copy link

Change https://golang.org/cl/79215 mentions this issue: internal/poll: loop on EINTR in Read on Darwin

@golang golang locked and limited conversation to collaborators Nov 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants