Go programs hanging on Windows 10

Issue

I’ve been having issues with all Go programs hanging on Windows, even a simple Hello world program. I’ve reinstalled Golang multiple times with nothing changing. I can’t use Ctrl+X or Ctrl+D to close the program either. It’ll still spawn the process which will show up on Process Monitor. But I can’t kill it from there or from the command line.

There was a similar issue to this posted on reddit https://www.reddit.com/r/golang/comments/2lvnqk/not_even_hello_world_works/. But that still has no resolution.

The is the program I’m trying to get to run right now:

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}

Running it with go run -x gives this output:

WORK=C:\Users\User\AppData\Local\Temp\go-build882050150
mkdir -p $WORK\command-line-arguments\_obj\
mkdir -p $WORK\command-line-arguments\_obj\exe\
cd E:\go\src\github.com\test\hello
"C:\\Go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments.a" -trimpath "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -p main -complete -buildid 0180ed6e175ea3e4bc497fc21fe0319a733a9c8e -D _/E_/go/src/github.com/test/hello -I "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -pack "E:\\go\\src\\github.com\\test\\hello\\main.go"
cd .
"C:\\Go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments\\_obj\\exe\\main.exe" -L "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150" -w -extld=gcc -buildmode=exe -buildid=0180ed6e175ea3e4bc497fc21fe0319a733a9c8e "C:\\Users\\User\\AppData\\Local\\Temp\\go-build882050150\\command-line-arguments.a"
$WORK\command-line-arguments\_obj\exe\main.exe

After that it just sits there and dose nothing. Doesn’t matter what program I run it will always hang forever.

No idea where to go from here. I don’t really develop on Windows but I was trying to work with cross-compilation on Ubuntu and having run into this issue with the cross-compiled binary I thought I’d try compiling directly on Windows. But it appears my Windows just doesn’t like Golang compiled binaries.

Go version is 1.5.1 windows/amd64.

Here’s the output of go env:

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

Solution

Avast was being dumb. Disabled Avast and the programs all worked….

Of course leaving Avast disabled is not ideal so I had to figure out a way to exclude go files. Unfortunately there’s no way to exclude go compiled files themselves, unless you set up individual exclusions for the binaries. However excluding go specific directories will work.

I ended up excluding the installation location of go for me this was C:\Go and the directory of GOPATH E:\go for me.

This worked for the most part as long as binaries were run from either of those two directories, but I was still having issues with using the go run command. Using the go run -x command I was able to find out where Go was putting the temporary compiled binaries. This ended up being at C:\Users\username\AppData\Local\Temp\go-build1234\. However go would create a new directory each time I used go run so I had to create an exclusion on Avast with two wildcards set C:\Users\username\AppData\Local\Temp\go-build*\*. Now programs will run correctly.

These are the exclusions I ended up with:
Go Avast exclusions

Answered By – JDWardle

Answer Checked By – Gilberto Lyons (GoLangFix Admin)

Leave a Reply

Your email address will not be published.