<p dir="auto">The go version is <code class="notranslate">1.5.1</code>.</p>
<p dir="auto">Here is the program:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;fmt&quot;
    &quot;runtime&quot;
    &quot;time&quot;
)

func test2() {
    for i := 1; ; i++ {
        fmt.Println(i, time.Now())
    }
}

func test() {
    a := 100
    for i := 1; i &lt; 1000; i++ {
        a = i*100/i + a
    }
}

func main() {
    runtime.GOMAXPROCS(2)
    go test2()
    for {
        test()
    }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
    <span class="pl-s">"fmt"</span>
    <span class="pl-s">"runtime"</span>
    <span class="pl-s">"time"</span>
)

<span class="pl-k">func</span> <span class="pl-en">test2</span>() {
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">:=</span> <span class="pl-c1">1</span>; ; <span class="pl-s1">i</span><span class="pl-c1">++</span> {
        <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s1">i</span>, <span class="pl-s1">time</span>.<span class="pl-en">Now</span>())
    }
}

<span class="pl-k">func</span> <span class="pl-en">test</span>() {
    <span class="pl-s1">a</span> <span class="pl-c1">:=</span> <span class="pl-c1">100</span>
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">:=</span> <span class="pl-c1">1</span>; <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">1000</span>; <span class="pl-s1">i</span><span class="pl-c1">++</span> {
        <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">i</span><span class="pl-c1">*</span><span class="pl-c1">100</span><span class="pl-c1">/</span><span class="pl-s1">i</span> <span class="pl-c1">+</span> <span class="pl-s1">a</span>
    }
}

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">runtime</span>.<span class="pl-en">GOMAXPROCS</span>(<span class="pl-c1">2</span>)
    <span class="pl-k">go</span> <span class="pl-en">test2</span>()
    <span class="pl-k">for</span> {
        <span class="pl-en">test</span>()
    }
}</pre></div>
<p dir="auto">Note that I configure <strong>two threads</strong> to run goroutines.<br>
The main goroutine would block one thread, while the test2() goroutine would run in another thread.<br>
However, the result is that, the test2() runs a bit, but after some random interval, it hangs (do not output anything); the main goroutine continue to run test() without problem.</p>
<p dir="auto">If I add some function call into the test(), e.g.</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="func test() {
    ...
    syscall.Getgid()
}"><pre class="notranslate"><span class="pl-k">func</span> <span class="pl-en">test</span>() {
    <span class="pl-c1">...</span>
    <span class="pl-s1">syscall</span>.<span class="pl-en">Getgid</span>()
}</pre></div>
<p dir="auto">Then the test() and test2() would run in parallel as expected.</p>
<p dir="auto">I try to do panic after some counts (estimated to be after the test2() hangs) within the loop to call test():</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    for i := 1; i &lt; 10000000000; i++ {
        if i == 1000000 {
            panic(&quot;hello&quot;)
        }
        test()
    }"><pre class="notranslate">    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">:=</span> <span class="pl-c1">1</span>; <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">10000000000</span>; <span class="pl-s1">i</span><span class="pl-c1">++</span> {
        <span class="pl-k">if</span> <span class="pl-s1">i</span> <span class="pl-c1">==</span> <span class="pl-c1">1000000</span> {
            <span class="pl-en">panic</span>(<span class="pl-s">"hello"</span>)
        }
        <span class="pl-en">test</span>()
    }</pre></div>
<p dir="auto">Then it shows the backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="goroutine 1 [running]:
main.main()
    /tmp/tmp.go:30 +0xb1

goroutine 5 [runnable]:
runtime.Gosched()
    /usr/local/go/src/runtime/proc.go:166 +0x14
time.Time.Format(0xecd820010, 0x37614ae4, 0x593740, 0x523840, 0x27, 0x0, 0x0)
    /usr/local/go/src/time/format.go:431 +0x135
time.Time.String(0xecd820010, 0x37614ae4, 0x593740, 0x0, 0x0)
    /usr/local/go/src/time/format.go:401 +0x54
time.(*Time).String(0xc8204977a0, 0x0, 0x0)
    &lt;autogenerated&gt;:1 +0xad
fmt.(*pp).handleMethods(0xc820068000, 0xc800000076, 0x0, 0xc820071c01)
    /usr/local/go/src/fmt/print.go:730 +0x633
fmt.(*pp).printArg(0xc820068000, 0x5024a0, 0xc8204977a0, 0x76, 0x0, 0xc81ffdb400)
    /usr/local/go/src/fmt/print.go:806 +0x4a5
fmt.(*pp).doPrint(0xc820068000, 0xc820071f78, 0x2, 0x2, 0x101)
    /usr/local/go/src/fmt/print.go:1254 +0x258
fmt.Fprintln(0x7f18e5d2f000, 0xc820026010, 0xc820071f78, 0x2, 0x2, 0x40b7f0, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:254 +0x67
fmt.Println(0xc820071f78, 0x2, 0x2, 0x5024a0, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:264 +0x73
main.test2()
    /tmp/tmp.go:12 +0x17f
created by main.main
    /tmp/tmp.go:27 +0x3c
exit status 2"><pre class="notranslate"><code class="notranslate">goroutine 1 [running]:
main.main()
    /tmp/tmp.go:30 +0xb1

goroutine 5 [runnable]:
runtime.Gosched()
    /usr/local/go/src/runtime/proc.go:166 +0x14
time.Time.Format(0xecd820010, 0x37614ae4, 0x593740, 0x523840, 0x27, 0x0, 0x0)
    /usr/local/go/src/time/format.go:431 +0x135
time.Time.String(0xecd820010, 0x37614ae4, 0x593740, 0x0, 0x0)
    /usr/local/go/src/time/format.go:401 +0x54
time.(*Time).String(0xc8204977a0, 0x0, 0x0)
    &lt;autogenerated&gt;:1 +0xad
fmt.(*pp).handleMethods(0xc820068000, 0xc800000076, 0x0, 0xc820071c01)
    /usr/local/go/src/fmt/print.go:730 +0x633
fmt.(*pp).printArg(0xc820068000, 0x5024a0, 0xc8204977a0, 0x76, 0x0, 0xc81ffdb400)
    /usr/local/go/src/fmt/print.go:806 +0x4a5
fmt.(*pp).doPrint(0xc820068000, 0xc820071f78, 0x2, 0x2, 0x101)
    /usr/local/go/src/fmt/print.go:1254 +0x258
fmt.Fprintln(0x7f18e5d2f000, 0xc820026010, 0xc820071f78, 0x2, 0x2, 0x40b7f0, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:254 +0x67
fmt.Println(0xc820071f78, 0x2, 0x2, 0x5024a0, 0x0, 0x0)
    /usr/local/go/src/fmt/print.go:264 +0x73
main.test2()
    /tmp/tmp.go:12 +0x17f
created by main.main
    /tmp/tmp.go:27 +0x3c
exit status 2
</code></pre></div>
<p dir="auto">So why test2() goroutine hangs?</p>
<p dir="auto">by <strong>mklencke</strong>:</p>
<pre class="notranslate">What steps will reproduce the problem?
1. Try to 'go build' or 'go run' code that imports a package that does not exist, for
example the old "rand" package

What is the expected output?

Successful output of 'go run'.

What do you see instead?

A panic trace

Which compiler are you using (5g, 6g, 8g, gccgo)?

8g

Which operating system are you using?

Linux

Which revision are you using?  (hg identify)

54016655b9d7+ tip

Please provide any additional information below.

Simple fix is attached</pre>
<p dir="auto">Attachments:</p>
<ol dir="auto">
<li><a href="https://storage.googleapis.com/go-attachment/2813/0/buildpanic.diff" rel="nofollow">buildpanic.diff</a> (351 bytes)</li>
</ol>