Move environment variable set outside goroutine, to avoid race condition