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
Assignees
Milestone

Comments

@tibbes
Copy link
Contributor

@tibbes 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 this to the Go1.10 milestone Nov 21, 2017
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Nov 21, 2017

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 21, 2017

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 21, 2017

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

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 21, 2017

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

@gopherbot gopherbot closed this in 3fec6da Nov 22, 2017
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.