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: Stat() returns inconsistent error on Windows #29119

Closed
Xjs opened this issue Dec 6, 2018 · 8 comments
Closed

os: Stat() returns inconsistent error on Windows #29119

Xjs opened this issue Dec 6, 2018 · 8 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows release-blocker
Milestone

Comments

@Xjs
Copy link
Contributor

Xjs commented Dec 6, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11.1 windows/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\jannis.schnitzer\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:/Users/jannis.schnitzer
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\tools\msys64\tmp\go-build255706334=/tmp/go-build -gno-record-gcc-switches

What did you do?

Execute the following program under Windows:

package main

import (
        "fmt"
        "os"
)

func main() {
        var err error
        _, err = os.Stat("doesnotexist")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("doesnotexist/")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("/doesnotexist")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("/doesnotexist/")
        fmt.Println(err, os.IsNotExist(err))
}

What did you expect to see?

All four lines should output the same error message. (Like on https://play.golang.org/p/X0RVDSjWRmi)

What did you see instead?

$ go run stat.go
FindFirstFile doesnotexist: The system cannot find the file specified. true
FindFirstFile doesnotexist/: The parameter is incorrect. false
FindFirstFile /doesnotexist: The system cannot find the file specified. true
FindFirstFile /doesnotexist/: The system cannot find the path specified. true

The second line (os.Stat("doesnotexist/")) produces a different error. Particularly os.IsNotExist(os.Stat("relative_path_that_doesnt_exist_and_ends_in_a_slash/")) is unexpectedly false.

Linux and macOS behave as expected.

@tklauser
Copy link
Member

tklauser commented Dec 6, 2018

@cgopalan
Copy link

cgopalan commented Dec 6, 2018

FYI This does not happen in version 1.10.3

λ go version
go version go1.10.3 windows/amd64
λ go run teststat.go
CreateFile doesnotexist: The system cannot find the file specified. true
CreateFile doesnotexist/: The system cannot find the file specified. true
CreateFile /doesnotexist: The system cannot find the file specified. true
CreateFile /doesnotexist/: The system cannot find the file specified. true

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Dec 6, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Dec 6, 2018
@alexbrainman
Copy link
Member

FYI This does not happen in version 1.10.3

This does not happen on the tip either (I am using 9be01c2)

C:\>u:\test
CreateFile doesnotexist: The system cannot find the file specified. true
CreateFile doesnotexist/: The system cannot find the file specified. true
CreateFile /doesnotexist: The system cannot find the file specified. true
CreateFile /doesnotexist/: The system cannot find the file specified. true

C:\>

Alex

@cgopalan
Copy link

cgopalan commented Dec 9, 2018

@alexbrainman I just saw that the test i wrote failed. So this is not an issue in the latest master but was only an issue in the 1.11 release?
FYI I did test on the latest go release which I downloaded and I did get the error.

@alexbrainman
Copy link
Member

@alexbrainman I just saw that the test i wrote failed. So this is not an issue in the latest master but was only an issue in the 1.11 release?

This issues does exists in go1.11. But, I believe, it has been fixed on current tip.

Alex

@cgopalan
Copy link

cgopalan commented Dec 9, 2018

@alexbrainman oh so should I just close the PR?

@alexbrainman
Copy link
Member

@alexbrainman oh so should I just close the PR?

I think your PR is not need. There is no problem here to fix.

Alex

@cgopalan
Copy link

cgopalan commented Dec 9, 2018

@alexbrainman ok will close it then. @Xjs seems like this is fixed in master.

endocrimes added a commit to hashicorp/nomad that referenced this issue Jul 22, 2019
There's a bug in go1.11 that causes some io operations on windows to
return incorrect errors for some cases when Stat-ing files. To avoid
upgrading to go1.12 in a point release, here we loosen up the cases
where we will attempt to create fifos, and add some logging of
underlying stat errors to help with debugging.
schmichael added a commit to hashicorp/nomad that referenced this issue Jul 22, 2019
notnoop pushed a commit to hashicorp/nomad that referenced this issue Aug 24, 2019
Revert e012612 now that we are running
with Golang 1.12, and golang/go#29119 is no
longer relevant.
@golang golang locked and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants