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

cmd/go: go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. #29093

Closed
jcuan opened this issue Dec 4, 2018 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@jcuan
Copy link

jcuan commented Dec 4, 2018

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

$ go version
go version go1.11.2 windows/amd64

Does this issue reproduce with the latest release?

yes

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

windows 10 1803
10.0.17134
go env Output
$ go env
go version go1.11.2 windows/amd64
PS D:\code\go> go env
set GOARCH=amd64
set GOBIN=D:\tools\gobin
set GOCACHE=C:\Users\SHEXIA~1\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\code\go
set GOPROXY=
set GORACE=
set GOROOT=D:\tools\go11
set GOTMPDIR=
set GOTOOLDIR=D:\tools\go11\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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\SHEXIA~1\AppData\Local\Temp\go-build536614342=/tmp/go-build -gno-record-gcc-switches

What did you do?

#build successfully
PS D:\code\go\src> go build -o out.exe .\main.go
#update code, build failed
PS D:\code\go\src> go build -o out.exe .\main.go
open C:\Users\SHEXIA~1\AppData\Local\Temp\go-build047301674\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.
PS D:\code\go\src> go build -o out.exe .\main.go
open C:\Users\SHEXIA~1\AppData\Local\Temp\go-build838661906\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.
#wait a few minutes, build successfully again
PS D:\code\go\src> go build -o out.exe .\main.go
@ianlancetaylor ianlancetaylor changed the title go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. cmd/go: go build error. open C:\Users\...\a.out.exe: The process cannot access the file because it is being used by another process. Dec 5, 2018
@ianlancetaylor
Copy link
Contributor

Is this repeatable? What are the contents of main.go?

@ianlancetaylor ianlancetaylor added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 5, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Dec 5, 2018
@jcuan
Copy link
Author

jcuan commented Dec 5, 2018

@ianlancetaylor

This problem happens every time after I use go build .The Contents of main.go is simple and all my projects have this problem.

package main

import "fmt"

func main() {
    fmt.Println("jcuan")
}

@agnivade
Copy link
Contributor

agnivade commented Dec 5, 2018

This problem happens every time after I use go build .

That does not seem to match this statement of yours.

#wait a few minutes, build successfully again

So it looks like some process is possibly using a.out.exe for some time. I don't know what is the lsof equivalent in Windows, but are you sure that no process is actually using a.out.exe ?

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 5, 2018
@jcuan
Copy link
Author

jcuan commented Dec 5, 2018

@agnivade @ianlancetaylor

This problem happens every time after I use go build .

I mean I must wait a few minutes in order to build successfully again almost every time after using go build.

Now, I find that maybe it's caused by vscode/go extension in vscode. Yesterday, I turn off vscode and use notepad to edit code, which doesn't fix this problem. But today, I rebooted my computer and didn't open vscode before using go build and I didn't encounter this problem again after many tries. Then I opened vscode and this problem appeared again but the probability was very low.

Thank you both~ 😁

@jcuan jcuan closed this as completed Dec 5, 2018
@ghost
Copy link

ghost commented Jun 18, 2019

This solution helps for me. You can try it.
It seems that vscode is the cause of the problem.

@wusi1027
Copy link

it happens almost every time when using go version >=1.11(I've tried 1.11,1.12,1.13).
but it disappears when using go 1.9 or 1.10.
my env:
windows10, no IDE, just cmd/go build

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants