-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: possible regression from Go 1.23 to Go 1.24 when opening DevNull with O_TRUNC #71752
Comments
I should clarify that not using
but that possibly just papers over an unintentional regression that should be fixed regardless. |
This is most likely due to https://go.dev/cl/618836 for #38225. It's weird to pass |
To be clear, the flags I was passing in the real program were
Should this be milestoned for a backport fix to 1.24? |
Thanks for the We should probably backport but let's give @qmuntal a chance to take a look. It may be that we have to special case |
Sounds good. There's no rush from my side, as thankfully I can work around the bug for now. |
Weird, I can't reproduce this regression locally on a real Windows machine. Go 1.23 didn't support truncating >type main.go
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0)
fmt.Println(f != nil, err)
}
>go1.23.6 run main.go
false open NUL: Incorrect function.
>go1.24.0 run main.go
false open NUL: Incorrect function. Could it be an issue with Wine? If that's the case, then IMO this issue belongs to Wine, not to Go. Another option would be to special case |
I don't think this issue relates to Wine; I originally uncovered it on GitHub Actions via their windows-2022 runner, which as far as I can tell runs real Windows. See https://github.com/mvdan/sh/actions/runs/13274870177/job/37062363963, succeeding on Go 1.23.5, and https://github.com/mvdan/sh/actions/runs/13274870177/job/37062364367, failing on Go 1.24.0. Perhaps the way I reduced the failing test made it only show the regression on Wine, but not on real Windows? If so, try running My only other guess is that, somehow, this regression affects Wine and the version of Windows used by GitHub Actions, but not the one you have installed. |
Thanks for the pointer, I can reproduce it now. Setting the
Worth noting that the function fails if Will investigate and report back. |
Thanks! FWIW I don't oppose a conclusion like "never use O_CREATE or O_TRUNC on DevNull as it may fail on some platforms". This is just not something that is documented or warned about right now. |
Change https://go.dev/cl/650276 mentions this issue: |
Thanks for the fix! That's the sort of fix I imagined might be necessary. Just so I understand, I assume your reproducer above, as well as the added test in the CL, now pass on your Windows box. Interestingly, they still seem to fail on wine for me, if I cherry pick your commit on master:
Lots of other tests fail for me with Wine via |
Yep, it doesn't create any file. It is a bit confusing because the NUL device (as other Windows devices) always exist, but behave as if they were brand new files (they don't have state) when opening them regardless of the creation mode you use. |
@gopherbot please backport this to go1.24 release. This issue causes a regression when opening os.DevNull with the os.O_TRUNC bit set. |
Backport issue(s) opened: #71836 (for 1.24). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/650597 mentions this issue: |
…n Windows There is no need for syscall.OpenFile to truncate newly created files. Some special Windows files, like the NUL device, can't be truncated, so we should avoid truncating unless it is really necessary. For #71752 Fixes #71836 Change-Id: I8238048594f706f6a5281053d55cfe3dc898828d Reviewed-on: https://go-review.googlesource.com/c/go/+/650276 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> (cherry picked from commit 4267fd3) Reviewed-on: https://go-review.googlesource.com/c/go/+/650597 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Reviewed-by: Quim Muntal <[email protected]>
What version of Go are you using (
go version
)?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
OutputWhat did you do?
Take the following program:
Then I run it on the latest Go 1.23 and 1.24, on both Linux (the host) and Windows (via wine):
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
, akaNUL
on Windows, withO_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.
The text was updated successfully, but these errors were encountered: