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

Comments

@Xjs
Copy link
Contributor

@Xjs 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 tklauser added the OS-Windows label Dec 6, 2018
@tklauser

This comment has been minimized.

Copy link
Member

@tklauser tklauser commented Dec 6, 2018

@cgopalan

This comment has been minimized.

Copy link

@cgopalan 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
@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Dec 7, 2018

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

This comment has been minimized.

Copy link

@cgopalan 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

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman 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?

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

Alex

@cgopalan

This comment has been minimized.

Copy link

@cgopalan cgopalan commented Dec 9, 2018

@alexbrainman oh so should I just close the PR?

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Dec 9, 2018

@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

This comment has been minimized.

Copy link

@cgopalan cgopalan commented Dec 9, 2018

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

@yilunzhang yilunzhang mentioned this issue Feb 28, 2019
1 of 9 tasks complete
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
logmon: Workaround golang/go#29119
notnoop added 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.