Get tmp stuff in $GOTMPDIR instead of /tmp?

1,329 views
Skip to first unread message

per...@gmail.com

unread,
Aug 22, 2019, 10:55:05 AM8/22/19
to golang-nuts
I get a bloated /tmp-dir (in just a few days I get tens of thousands of folders named /tmp/go-build828718408 etc.) so I tried to set $GOTMPDIR, but nothing ends up there. (From what I understand of the documentation the purpose of GOTMPDIR is to move tmp stuff, see e.g. line 1471 of https://golang.org/src/cmd/go/alldocs.go?h=GOTMPDIR, or release notes of 1.10 https://golang.org/doc/go1.10).

Am I using things wrong?

$ go version
go version go1
.12.6 linux/amd64

$ echo $GOTMPDIR
/tmp/go-builds

$ ls $GOTMPDIR
please
-end-up-here.txt

$ go build
/test/this/that/etc
[...]

$ ls $GOTMPDIR
please
-end-up-here.txt


Kind regards,
Per the go-noob.

Wagner Riffel

unread,
Aug 22, 2019, 11:34:31 AM8/22/19
to per...@gmail.com, golang-nuts
On Thu, Aug 22, 2019 at 11:54 AM <per...@gmail.com> wrote:
>
> Am I using things wrong?

go build uses GOCACHE, not GOTMPDIR. See go help environment.

- wgr

Wagner Riffel

unread,
Aug 22, 2019, 12:02:39 PM8/22/19
to per...@gmail.com, golang-nuts
On Thu, Aug 22, 2019 at 12:33 PM Wagner Riffel <wgrr...@gmail.com> wrote:
> go build uses GOCACHE, not GOTMPDIR. See go help environment.

Sorry, i was wrong, those are supposed to be temporary files, and they
are going correctly to GOTMPDIR for me, not sure what your problem is.

- wgr

Ian Lance Taylor

unread,
Aug 23, 2019, 10:04:50 AM8/23/19
to per...@gmail.com, golang-nuts
On Thu, Aug 22, 2019 at 7:55 AM <per...@gmail.com> wrote:
>
> I get a bloated /tmp-dir (in just a few days I get tens of thousands of folders named /tmp/go-build828718408 etc.)

That is odd in itself. The go-buildNNNNN directories should normally
be deleted when the go command completes. Are you routinely killing
your go commands before they complete and have a chance to remove the
temporary directory?


> so I tried to set $GOTMPDIR, but nothing ends up there. (From what I understand of the documentation the purpose of GOTMPDIR is to move tmp stuff, see e.g. line 1471 of https://golang.org/src/cmd/go/alldocs.go?h=GOTMPDIR, or release notes of 1.10 https://golang.org/doc/go1.10).
>
> Am I using things wrong?
>
> $ go version
> go version go1.12.6 linux/amd64
>
> $ echo $GOTMPDIR
> /tmp/go-builds
>
> $ ls $GOTMPDIR
> please-end-up-here.txt
>
> $ go build/test/this/that/etc
> [...]
>
> $ ls $GOTMPDIR
> please-end-up-here.txt

Setting GOTMPDIR should work. What shell are you using? Did you
"export GOTMPDIR"?

Note that, as mentioned above, an ordinary go build will create a
temporary directory in GOTMPDIR and then delete it. So it's normal to
not see anything there after the go command completes. You can verify
the directory it uses by running "go build -work" (in which case it
will not delete the temporary directory).

Ian

Peter Weinberger (温博格)

unread,
Aug 23, 2019, 10:34:28 AM8/23/19
to Ian Lance Taylor, golang-nuts
This is routinely happening to me too, on linux. My go commands are go build *.go
The left-over directories are empty
I'm on go1.12.5 linux/amd64

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU-U_2Rz6UB1TUijdVyRSR-BJxxQdXgGVbJz4dX2p3vaA%40mail.gmail.com.

Ian Lance Taylor

unread,
Aug 23, 2019, 10:44:14 AM8/23/19
to Peter Weinberger (温博格), golang-nuts
On Fri, Aug 23, 2019 at 7:34 AM Peter Weinberger (温博格) <p...@google.com> wrote:
>
> This is routinely happening to me too, on linux. My go commands are go build *.go
> The left-over directories are empty
> I'm on go1.12.5 linux/amd64

Well, that is ungood. And I don't see it myself. Can you figure out
a way to reproduce the problem?

Ian

per...@gmail.com

unread,
Aug 26, 2019, 5:38:03 AM8/26/19
to golang-nuts
The only weird thing I've done is some manual upgrade of go (Ubuntu had not gotten modules so I did some wget thing to get a newer version I think). I do go build in bash because the modules thing has broken VS Code (or I have a mismatch of VS Code plugins, etc. etc. -- all acceptable pains). I sometimes do go test but not that often. I'm working with go buffalo to make a web-thing, and I'm also working with sqlboiler.

Here are some environment details:

$ bash --version
bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
[...]

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/<username>/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/<username>/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR="/tmp/go-builds"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-builds/go-build308894691=/tmp/go-build -gno-record-gcc-switches"

$ env | grep "^G"
GDM_LANG=en_US
GTK_OVERLAY_SCROLLING=0
GLADE_CATALOG_PATH=:
GLADE_MODULE_PATH=:
GO111MODULE=on
GOTMPDIR=/tmp/go-builds
GLADE_PIXMAP_PATH=:
GTK_MODULES=gail:atk-bridge
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
GDMSESSION=xubuntu


$ go version
go version go1.12.6 linux/amd64

$ cat /etc/issue
Ubuntu 18.04.3 LTS \n \l

$ ls /tmp | grep go-build | wc -l
38302

$ ls /tmp/go-builds | grep go-build | wc -l
0

$ uptime
 11:37:18 up 4 days,  3:20,  1 user,  load average: 0,58, 0,54, 0,47
>> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages