Description
What version of Go are you using (go version
)?
$ go version go version go1.24.0 linux/amd64
Does this issue reproduce with the latest release?
Yes; and it also reproduces on tip.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env AR='ar' CC='gcc' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_ENABLED='1' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' CXX='g++' GCCGO='gccgo' GO111MODULE='' GOAMD64='v1' GOARCH='amd64' GOAUTH='netrc' GOBIN='' GOCACHE='/home/mvdan/.cache/go-build' GOCACHEPROG='' GODEBUG='' GOENV='/home/mvdan/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFIPS140='off' GOFLAGS='' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3169099861=/tmp/go-build -gno-record-gcc-switches' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMOD='/dev/null' GOMODCACHE='/home/mvdan/go/pkg/mod' GONOPROXY='github.com/cue-unity' GONOSUMDB='github.com/cue-unity' GOOS='linux' GOPATH='/home/mvdan/go' GOPRIVATE='github.com/cue-unity' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/lib/go' GOSUMDB='sum.golang.org' GOTELEMETRY='on' GOTELEMETRYDIR='/home/mvdan/.config/go/telemetry' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.24.0' GOWORK='' PKG_CONFIG='pkg-config' uname -sr: Linux 6.13.2-arch1-1 LSB Version: n/a Distributor ID: Arch Description: Arch Linux Release: rolling Codename: n/a /usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.41. gdb --version: GNU gdb (GDB) 16.2
What did you do?
Take the following program:
$ cat f.go
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.OpenFile(os.DevNull, os.O_TRUNC, 0)
fmt.Println(f != nil, err)
}
Then I run it on the latest Go 1.23 and 1.24, on both Linux (the host) and Windows (via wine):
$ for goos in linux windows; do for go in go1.23.6 go1.24.0; do echo $goos $go; GOOS=$goos GOTOOLCHAIN=$go go run f.go; done; done
linux go1.23.6
true <nil>
linux go1.24.0
true <nil>
windows go1.23.6
true <nil>
windows go1.24.0
false open NUL: Invalid handle.
What did you expect to see?
Consistent behavior, or otherwise, some sort of changelog note in https://go.dev/doc/go1.24 to explain what happened and why.
What did you see instead?
It appears that opening os.DevNull
, aka NUL
on Windows, with O_TRUNC
is now deemed an invalid operation, when before it wasn't.
It's not clear to me whether the new behavior on Windows in terms of this edge case is correct or not, but it certainly caught me by surprise. Not only because it changed from Go 1.23, but also because on Linux the operation still works OK.
I am using Wine here as a quick way to test this, but this error happens on real Windows too; see https://github.com/mvdan/sh/actions/runs/13274870177, where go test
succeeded on Go 1.23 on Windows, but failed on Go 1.24 with the same "Incorrect function" errors.
I suspect one of @qmuntal's changes, perhaps https://go-review.googlesource.com/c/go/+/618835 or https://go-review.googlesource.com/c/go/+/620576, could have caused this?
My apologies for not having spotted this issue earlier; I test Go at master continuosuly, but only on Linux, as Wine only gets me so far.