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: remove temporary build directories when terminated by signal #39382

Open
jayconrod opened this issue Jun 3, 2020 · 2 comments
Open

cmd/go: remove temporary build directories when terminated by signal #39382

jayconrod opened this issue Jun 3, 2020 · 2 comments
Labels
Milestone

Comments

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Jun 3, 2020

Originally reported in golang/vscode-go#152.

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

$ go version
go version go1.14.4 darwin/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/installed"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/installed/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build036956176=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Interrupt go test or any other build command using ^C or with kill -SIGINT.

It's easy to reproduce this by setting GOTMPDIR to a local directory and then running a test that sleeps for a few seconds.

What did you expect to see?

No temporary go-build directories are left behind.

What did you see instead?

Directories with names like go-build312263156 are left behind.

go test should trap the signal, delete the work directory, and exit gracefully. It should not trim the build cache or do anything else that might take a long time (which it normally does when exiting).

Fixing this would be non-trivial: we'll need to plumb contexts through to network, build, and test operations to handle the cancellation. We probably want to do that anyway though for tracing.

cc @hakim @bcmills @matloob

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 3, 2020

we'll need to plumb contexts through to network, build, and test operations to handle the cancellation

Will contexts be enough? They do provide cancellation, but there won't be a way for the main goroutine to wait for the cleanup process (deleting temporary directories) to finish.

@jayconrod
Copy link
Contributor Author

@jayconrod jayconrod commented Jun 3, 2020

Cleaning up build directories happens in base.Exit, which is run from the main goroutine. I think that would be mostly unchanged. We'd just get there faster by cancelling anything that takes a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.