golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 610 forks source link

gomock_reflect_123456789 files are left and not deleted #264

Closed hejnm1am closed 4 years ago

hejnm1am commented 5 years ago

I am using go modules if it is important.

poy commented 5 years ago

It looks like we are removing the temp file via a defer: https://github.com/golang/mock/blob/c20582278a829e4b3259747a3ce0eceb1763ee13/mockgen/reflect.go#L99

What version of gomock are you using? Can you also show me the output of go env?

hejnm1am commented 5 years ago

Go env here:

set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\xxxx\AppData\Local\go-build set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\Users\xxxx\go 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=C:\git\XXXX\YYYY\Src\ZZZZ\AAAA\BBBB\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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\xxxx\AppData\Local\Temp\go-build836306630=/tmp/go-build -gno-record-gcc-switches

I am using Go modules. I don't know if the name of Src directory in $GOMOD is important, but it has no relation to project dir. It is just name of directory if my git repo. Actual GO project is deep inside.

I don't know how to get version of gomock. But I just run 'go install github.com/golang/mock/mockgen' and the problem is the same. I installed mockgen no more than 14 days ago anyway.

I also didn't notice that I am running everything from minGW on Windows 7.

Also this happens every time. It doesn't seem like random race condition.

poy commented 5 years ago

One thing I'm noticing is that the error returned from os.RemoveAll(tmpDir) is not being logged or anything. Can you build gomock from the log-temp-remove-err branch? I've added logic to log the error if it fails to delete the temp directory.

hejnm1am commented 5 years ago

The branch log-temp-remove-err still point to the same commit as master. Also there is no logging in defer func() { os.RemoveAll(tmpDir) }() and no commit from time you wrote.

Can you please check you've pushed to the repo correctly?

poy commented 5 years ago

@hejnm1am Sorry about that. I've ACTUALLY pushed a commit to that branch.

hejnm1am commented 5 years ago

2019/02/26 12:12:07 failed to remove temp directory: remove C:\xxx\yyy\gomock_reflect_422809967\prog.bin.exe: Access is denied.

Any hints how to find out why is access denied?

poy commented 5 years ago

I'm not an expert at windows. You might try to look into what policies you have and perhaps try moving your temp directory to a different location.

hejnm1am commented 5 years ago

I actually guess its some kind of race condition. Sometimes prog.bin.exe is deleted (so only empty directory remains) and sometimes not.

Also cannot this be because of I am using go with modules (go.mod)? Other people using similar setup have same problems in my team.

I find my setup as a pretty default one.

poy commented 5 years ago

I actually guess its some kind of race condition. Sometimes prog.bin.exe is deleted (so only empty directory remains) and sometimes not.

This is an interesting idea. So I've noticed that there is another place where a file is being removed:

https://github.com/golang/mock/blob/c20582278a829e4b3259747a3ce0eceb1763ee13/mockgen/reflect.go#L60

However, that temp file has a different prefix so I would expect them to be in different locations. Also that temp file is not prog.bin.exe.

Also cannot this be because of I am using go with modules (go.mod)?

I wouldn't expect go modules would have any have any sway on a temp directory being removed.

Are you able to delete the temp directory manually?

codyoss commented 4 years ago

Closing due to age with no response. Please feel free to reopen if you have more details to share!