Repository: go
Issue: runtime: "fatal error: runtime: pipe failed" on macOS Big Sur
Labels: NeedsInvestigation,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.16.1 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes.


### What operating system and processor architecture are you using (`go env`)?
Macbook Air M1 (Apple Silicon ARM64)
macOS Big Sur go1.16.1 darwin/amd64

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/vojtechvitek/Library/Caches/go-build"
GOENV="/Users/vojtechvitek/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/vojtechvitek/go/pkg/mod"
GONOPROXY="[redacted]"
GONOSUMDB="[redacted]"
GOOS="darwin"
GOPATH="/Users/vojtechvitek/go"
GOPRIVATE="[redacted]"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/vojtechvitek/VojtechVitek/rerun/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/23/vc4gzw8n52gc17yx4wfqfj3c0000gn/T/go-build4066643553=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

```
$ go get github.com/VojtechVitek/rerun/cmd/rerun@v0.0.3

$ rerun -watch . -run echo "Rerunning command."
$ echo Rerunning command.
Rerunning command.
runtime: pipe failed with 91746476
fatal error: runtime: pipe failed

goroutine 6 [running]:
runtime.throw(0x10f41e8, 0x14)
	/usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc00003ed38 sp=0xc00003ed08 pc=0x1034032
runtime.netpollinit()
	/usr/local/go/src/runtime/netpoll_kqueue.go:34 +0x1a5 fp=0xc00003edc0 sp=0xc00003ed38 pc=0x102fe05
runtime.netpollGenericInit()
	/usr/local/go/src/runtime/netpoll.go:123 +0x67 fp=0xc00003edd8 sp=0xc00003edc0 pc=0x102f827
runtime.doaddtimer(0xc000024000, 0xc000060058)
	/usr/local/go/src/runtime/time.go:281 +0x185 fp=0xc00003ee30 sp=0xc00003edd8 pc=0x1054905
runtime.addtimer(0xc000060058)
	/usr/local/go/src/runtime/time.go:269 +0xad fp=0xc00003ee68 sp=0xc00003ee30 pc=0x10546ed
time.startTimer(0xc000060058)
	/usr/local/go/src/runtime/time.go:212 +0x2b fp=0xc00003ee80 sp=0xc00003ee68 pc=0x1065b0b
time.NewTimer(0x7fffffffffffffff, 0x0)
	/usr/local/go/src/time/sleep.go:96 +0xc5 fp=0xc00003eec0 sp=0xc00003ee80 pc=0x109bcc5
github.com/VojtechVitek/rerun.(*Watcher).Watch.func2(0xc0000b8000, 0xbebc200, 0xc000283b60)
	/Users/vojtechvitek/go/pkg/mod/github.com/!vojtech!vitek/rerun@v0.0.3/watcher.go:88 +0x235 fp=0xc00003efc8 sp=0xc00003eec0 pc=0x10c3fb5
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00003efd0 sp=0xc00003efc8 pc=0x1068841
created by github.com/VojtechVitek/rerun.(*Watcher).Watch
	/Users/vojtechvitek/go/pkg/mod/github.com/!vojtech!vitek/rerun@v0.0.3/watcher.go:82 +0x12d

goroutine 1 [chan receive]:
main.main()
	/Users/vojtechvitek/go/pkg/mod/github.com/!vojtech!vitek/rerun@v0.0.3/cmd/rerun/main.go:112 +0x3cb

goroutine 18 [syscall]:
syscall.syscall6(0x10c03c0, 0x3, 0x0, 0x0, 0xc000038688, 0xa, 0x11d0920, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/sys_darwin.go:41 +0x2e
golang.org/x/sys/unix.kevent(0x3, 0x0, 0x0, 0xc000038688, 0xa, 0x11d0920, 0x0, 0x0, 0x0)
	/Users/vojtechvitek/go/pkg/mod/golang.org/x/sys@v0.0.0-20210309074719-68d13333faf2/unix/zsyscall_darwin_amd64.go:276 +0xa5
golang.org/x/sys/unix.Kevent(0x3, 0x0, 0x0, 0x0, 0xc000038688, 0xa, 0xa, 0x11d0920, 0x0, 0x0, ...)
	/Users/vojtechvitek/go/pkg/mod/golang.org/x/sys@v0.0.0-20210309074719-68d13333faf2/unix/syscall_bsd.go:429 +0x71
github.com/fsnotify/fsnotify.read(0x3, 0xc000038688, 0xa, 0xa, 0x11d0920, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/vojtechvitek/go/pkg/mod/github.com/fsnotify/fsnotify@v1.4.9/kqueue.go:511 +0x6e
github.com/fsnotify/fsnotify.(*Watcher).readEvents(0xc0000b2180)
	/Users/vojtechvitek/go/pkg/mod/github.com/fsnotify/fsnotify@v1.4.9/kqueue.go:274 +0x81b
created by github.com/fsnotify/fsnotify.NewWatcher
	/Users/vojtechvitek/go/pkg/mod/github.com/fsnotify/fsnotify@v1.4.9/kqueue.go:62 +0x199

goroutine 33 [syscall]:
os/signal.signal_recv(0x0)
	/usr/local/go/src/runtime/sigqueue.go:165 +0x9d
os/signal.loop()
	/usr/local/go/src/os/signal/signal_unix.go:23 +0x25
created by os/signal.Notify.func1.1
	/usr/local/go/src/os/signal/signal.go:151 +0x45

goroutine 5 [chan receive]:
main.main.func1(0xc0000b21e0, 0xc000056020)
	/Users/vojtechvitek/go/pkg/mod/github.com/!vojtech!vitek/rerun@v0.0.3/cmd/rerun/main.go:80 +0x3b
created by main.main
	/Users/vojtechvitek/go/pkg/mod/github.com/!vojtech!vitek/rerun@v0.0.3/cmd/rerun/main.go:79 +0x2f3
ERROR 2
```


### What did you expect to see?
`rerun -watch . -run echo "Rerunning command."`
On any file-system change, the `echo` command would run. This works well on other architectures. And I'd swear this used to work on Go 1.16rc1. However I can't find it anymore in the Go Download page, so I can't re-test it.


### What did you see instead?
`fatal error: runtime: pipe failed`


I'm sorry if this is insufficient bug report, but I don't have a clue what else to include. I'm not sure how to help debug this any further. Any help/guidance would be greatly appreciated.

During the crash, the program does this in the high-level:
- Runs an `os/exec` command in the background
- Listens on signals (`signal.Notify`)
- Watches FS changes via kqueue (https://github.com/fsnotify/fsnotify) 
- Spins up some internal timers (`time.NewTimer()`)

https://github.com/VojtechVitek/rerun