Skip to content

os: OpenFile using O_TRUNC and O_CREATE on a named pipe fails on windows #76071

@secDre4mer

Description

@secDre4mer

Go version

go version go1.25.3 windows/amd64

Output of go env in your module/workspace:

# go env
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\Max\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\Max\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Max\AppData\Local\Temp\go-build1595438883=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\Max\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Max\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\Max\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.25.3
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Call os.OpenFile with os.O_TRUNC (or os.Create) with an (existing) named pipe. Minimal working example:

package main

import (
	"os"
)

func main() {
	_, err := os.OpenFile(`\\.\pipe\test`, os.O_RDWR|os.O_TRUNC, 0666)
	if err != nil {
		panic(err)
	}
}

What did you see happen?

os.OpenFile returns an error.

What did you expect to see?

Since documentation for O_TRUNC states that it only applies to regular files:

O_TRUNC int = syscall.O_TRUNC // truncate regular writable file when opened.

a valid handle should be returned.

This was the behavior in go 1.23, which does not return an error in this case. Both 1.24 and 1.25, however, error.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions