go run requires internet connection?

208 views
Skip to first unread message

Tanmay Das

unread,
Apr 8, 2020, 4:17:36 PM4/8/20
to golang-nuts
Hey Gophers,
My very first post here.

Today I faced an unexpected power outage and I wanted to tinker with Go a little bit. I wrote a simple hello world program and ran
go run helloworld.go

Strangely the code didn't run. In fact, the terminal prompt never exited. I kept running the same command over and over again but no luck. I checked all my configurations, my env vars, etc. and everything was ok. After ruling out all the possibilities it suddenly hit me: what if Go actually requires an internet connection to run a program for no apparent reason? I waited for the electricity to come back and as soon as I was connected to the internet I ran `go run` command again and voilà! 

Is this behavior expected? If it is, why did the go authors make such a decision? I mean making the internet connectivity a dependency for the execution of a program sounds counter-productive to me, honestly. :(

Ian Lance Taylor

unread,
Apr 8, 2020, 4:25:21 PM4/8/20
to Tanmay Das, golang-nuts
An Internet connection is not required in general. But it is required
if you import packages that are not part of the standard library.
What was your program? What version of Go were you using? What is
the output of "go env"?

Ian

Marvin Renich

unread,
Apr 8, 2020, 4:30:31 PM4/8/20
to golang-nuts
* Tanmay Das <tanma...@gmail.com> [200408 12:17]:
> Hey Gophers,
> My very first post here.
>
> Today I faced an unexpected power outage and I wanted to tinker with Go a
> little bit. I wrote a simple hello world program and ran
> go run helloworld.go
>
> Strangely the code didn't run. In fact, the terminal prompt never exited. I
> kept running the same command over and over again but no luck. I checked
> all my configurations, my env vars, etc. and everything was ok. After
> ruling out all the possibilities it suddenly hit me: what if Go actually
> requires an internet connection to run a program for no apparent reason? I
> waited for the electricity to come back and as soon as I was connected to
> the internet I ran `go run` command again and voilą!
>
> Is this behavior expected? If it is, why did the go authors make such a
> decision? I mean making the internet connectivity a dependency for the
> execution of a program sounds counter-productive to me, honestly. :(

You didn't post any code, so it is really difficult to help you. No, Go
does not require an internet connection unless you write your program to
do so.

The best way to get help here is to go to https://play.golang.org/ and
paste your code there (replacing what is there). Then click on the
"Share" button, and you will get a link that you can copy and paste into
a message to this group.

This will allow us to see the code and help you unravel your problem.

...Marvin

Harald Weidner

unread,
Apr 8, 2020, 4:43:55 PM4/8/20
to golan...@googlegroups.com
Hello,

On Wed, Apr 08, 2020 at 06:00:19AM -0700, Tanmay Das wrote:

> go run helloworld.go
>
> Strangely the code didn't run. In fact, the terminal prompt never exited. I
> kept running the same command over and over again but no luck.

You can run "go run -x helloworld.go" to see what the toolchain is doing.

Harald

Tanmay Das

unread,
Apr 9, 2020, 5:13:34 AM4/9/20
to golang-nuts
It's a simple hello world program that doesn't require any go-gettable package:

package main

import (
"fmt"
)

func main() {
fmt.Println("Hello World")
}

Tanmay Das

unread,
Apr 9, 2020, 5:15:22 AM4/9/20
to golang-nuts
I also forgot to mention one thing. I was able to build the program using go build. Even the executable was there. It just didn't run until I connected to internet.

Tamás Gulácsi

unread,
Apr 9, 2020, 5:40:51 AM4/9/20
to golang-nuts
Is it in Windows? Any antivirus may be involved?

Tanmay Das

unread,
Apr 9, 2020, 5:54:04 AM4/9/20
to golang-nuts
No. OS X 10.15.3

Volker Dobler

unread,
Apr 9, 2020, 7:14:33 AM4/9/20
to golang-nuts
On Wednesday, 8 April 2020 18:17:36 UTC+2, Tanmay Das wrote:
Is this behavior expected? If it is, why did the go authors make such a decision? I mean making the internet connectivity a dependency for the execution of a program sounds counter-productive to me, honestly. :(

Well, go run does not just execute a program. It compiles
the program und executes the compiled binary. The execution
part doesn't need any internet connectivity, but the compilation
step _might_ need one of some dependencies are not available.
This is one of the many problems with go run.

But note that this is the case for each and every language:
You cannot run Java, C#, Rust, FORTRAN, R, whatnot code
if dependencies are missing and not retrievable.

V. 

Tanmay Das

unread,
Apr 9, 2020, 7:21:09 AM4/9/20
to golang-nuts
Hmm, it makes sense. Still, there should be some caching mechanism. If the internet connection can't be established, load the dep from the cache.

Brian Candler

unread,
Apr 9, 2020, 10:15:50 AM4/9/20
to golang-nuts
On Thursday, 9 April 2020 06:15:22 UTC+1, Tanmay Das wrote:
I also forgot to mention one thing. I was able to build the program using go build. Even the executable was there. It just didn't run until I connected to internet.


When you say "it just didn't run", do you mean with "go run ...", or directly running the executable that you just built?

If running the already-built executable hung, then I can only guess that Apple are using a central service to check the fingerprints of executables that haven't been seen before.  It would be interesting to run tcpdump at the same time, to see if it's trying to do DNS lookups for some Apple server.

I also remember there are settings where you can send Apple information about which applications you run (e.g. Preferences > Security & Privacy > Privacy > Analytics > Share Mac Analytics).  But I'd be surprised if it did that *before* the application started.

Tanmay Das

unread,
Apr 9, 2020, 11:01:31 AM4/9/20
to golang-nuts
Running the executable: `./helloworld`

Also note that, before building the executable, I tried running with `go run`, which of course, failed. I can't even say "Failed" because the go compiler was not throwing any error like Hey, since I need to download some dependencies even though your program doesn't have one, you might wanna try running the program later. The cursor just stuck in the terminal for eternity. I had to quit it with Ctrl + C.

Brian Candler

unread,
Apr 9, 2020, 11:11:04 AM4/9/20
to golang-nuts
On Thursday, 9 April 2020 12:01:31 UTC+1, Tanmay Das wrote:
Running the executable: `./helloworld`


OK, then clearly it's not an issue with finding our downloading dependencies: these will all have been resolved by the time the binary has been compiled and linked.

Therefore, I think it must be some issue with macOS being told to run an executable it hasn't seen before, making a network connection.

If you run it once successfully, and then remove the network connection, does it run again OK?  (I would hope that it caches the result)

Tanmay Das

unread,
Apr 9, 2020, 11:18:34 AM4/9/20
to golang-nuts
Therefore, I think it must be some issue with macOS being told to run an executable it hasn't seen before, making a network connection.
You are probably right.

 If you run it once successfully, and then remove the network connection, does it run again OK?
It does. 

Tanmay Das

unread,
Apr 9, 2020, 11:32:00 AM4/9/20
to golang-nuts
Thanks, everyone for your valuable comments. I think Brain is right. It might be an OS-related issue. I really like how active this group is. I look forward to coming back with more topics in the future. Stay Home. Stay Safe.


On Wednesday, April 8, 2020 at 10:17:36 PM UTC+6, Tanmay Das wrote:

Michael Jones

unread,
Apr 9, 2020, 11:55:10 AM4/9/20
to Tanmay Das, golang-nuts
Unable to reproduce the issue on MacOS Mojave 10.14.6, though I tried with gusto.

--
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/8fc3b552-f5c4-43de-94ba-4e0d4511f79a%40googlegroups.com.


--
Michael T. Jones
michae...@gmail.com

Personal

unread,
Apr 9, 2020, 1:17:18 PM4/9/20
to Tanmay Das, golang-nuts


> On 8 Apr 2020, at 20.00, Tanmay Das <tanma...@gmail.com> wrote:
>
> Hey Gophers,
> My very first post here.
>
> Today I faced an unexpected power outage and I wanted to tinker with Go a little bit. I wrote a simple hello world program and ran
> go run helloworld.go
>
> Strangely the code didn't run. In fact, the terminal prompt never exited. I kept running the same command over and over again but no luck. I checked all my configurations, my env vars, etc. and everything was ok. After ruling out all the possibilities it suddenly hit me: what if Go actually requires an internet connection to run a program for no apparent reason? I waited for the electricity to come back and as soon as I was connected to the internet I ran `go run` command again and voilà!
>

Can you attach the output of `go env` and your working directory? I am curious because I may have another issue that may related to this. Thank you.

Ronny Bangsund

unread,
Apr 9, 2020, 6:13:26 PM4/9/20
to golang-nuts


On Thursday, April 9, 2020 at 1:01:31 PM UTC+2, Tanmay Das wrote:
Running the executable: `./helloworld`
Maybe there's a log entry for your program specifically in Console (the GUI collecting macOS logs), or in one of the system logs.

If this is somehow related to GateKeeper, you could try making an exception for it:
spctl --add helloworld
(You'll get a popup to enter the admin password.)

Or removing all attributes:
xattr -d <your binary>

Although I'm not sure the last option will do much :)

David Riley

unread,
Apr 9, 2020, 8:07:00 PM4/9/20
to Michael Jones, Tanmay Das, golang-nuts
I feel like it's 10.15 where Apple really started doubling down on their "notarization" service? I haven't updated anything to it because it breaks (by design) a number of things I regularly use, so it would be hard to say, but that has to be frustrating for developers who can't be constantly online.


- Dave
Reply all
Reply to author
Forward
0 new messages