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 fails with permission error inside a temporary directory on Windows #42224

Open
zhaoyunxing92 opened this issue Oct 27, 2020 · 8 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@zhaoyunxing92
Copy link

zhaoyunxing92 commented Oct 27, 2020

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

$ go version
go version go1.15.3 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 GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\zyx\AppData\Local\go-build
set GOENV=C:\Users\zyx\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\gopath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\gopath
set GOPRIVATE=
set GOPROXY=https://goproxy.io,direct
set GOROOT=D:\software\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\software\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\code\github\go\go-mongo\go.mod
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\zyx~1\AppData\Local\Temp\go-build500345966=/tmp/go-build -gno-record-gcc-switches

What did you do?

go run main.go

What did you expect to see?

What did you see instead?

open C:\Users\zyx~1\AppData\Local\Temp\go-build933307734\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

@davecheney
Copy link
Contributor

davecheney commented Oct 27, 2020

Thank you for raising this issue. Anti virus software often causes problems on windows systems. Would you be able to temporarily disable your AV software and see if that makes a difference?

@zhaoyunxing92
Copy link
Author

zhaoyunxing92 commented Oct 27, 2020

Thank you for raising this issue. Anti virus software often causes problems on windows systems. Would you be able to temporarily disable your AV software and see if that makes a difference?

thank you for your reply,I can't close it,I wonder if modifying his build directory can be solved

@davecheney
Copy link
Contributor

davecheney commented Oct 27, 2020

As a workaround can you try using go build to build the binary, then run the resulting .exe and see if that helps?

@zhaoyunxing92
Copy link
Author

zhaoyunxing92 commented Oct 27, 2020

As a workaround can you try using go build to build the binary, then run the resulting .exe and see if that helps?

the same mistake,whether to change the directory of GOGCCFLAGS can be resolved,but it doesn't seem like it can be changed

@davecheney
Copy link
Contributor

davecheney commented Oct 27, 2020

the same mistake,

Can you please post the entire output you see. Do not use a screenshot.

whether to change the directory of GOGCCFLAGS can be resolved,but it doesn't seem like it can be changed

This seems unrelated. Please open a new issue so it can be addressed independently. Thank you

@zhaoyunxing92
Copy link
Author

zhaoyunxing92 commented Oct 27, 2020

the same mistake,

Can you please post the entire output you see. Do not use a screenshot.

whether to change the directory of GOGCCFLAGS can be resolved,but it doesn't seem like it can be changed

This seems unrelated. Please open a new issue so it can be addressed independently. Thank you

12:55 [xyz@docker go-mongo ] (develop) go build main.go
open C:\Users\zyx~1\AppData\Local\Temp\go-build060591562\b001\exe\a.out.exe: The process cannot access the file because it is being used by another process.

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 30, 2020
@dmitshur dmitshur added this to the Backlog milestone Oct 30, 2020
@dmitshur dmitshur changed the title The process cannot access the file because it is being used by another process. cmd/go: go build fails with permission error inside a temporary directory on Windows Oct 30, 2020
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 30, 2020
@dmitshur
Copy link
Contributor

dmitshur commented Oct 30, 2020

CC @jayconrod, @matloob, @bcmills.

@GronkeyKong
Copy link

GronkeyKong commented Jan 25, 2022

The problem is that if GOTMPDIR is not set, golang will sometimes build in that generic \Temp directory that is dangerous to allow as a generic exception to Kaspersky.

Assuming you've already added your GOPATH as an exception in Kaspersky (for example, "C:\Users<user>\go"...what worked for me was to

  1. add a new directory (I named mine "tmp" but you could probably name it a number of things) within that path, i.e., "C:\Users<user>\go\tmp"
  2. Set the golang environment variable GOTMPDIR to it...

go env -w GOTMPDIR="C:\Users<user>\go\tmp"

And the issue goes away. But note that I already added "C:\Users<user>\go" as an exception to Kaspersky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants