<h3 dir="auto">What version of Go are you using (<code class="notranslate">go version</code>)?</h3>
<p dir="auto">Tested on go1.6 darwin/amd64 and go1.6 linux/amd64</p>
<h3 dir="auto">What operating system and processor architecture are you using (<code class="notranslate">go env</code>)?</h3>
<p dir="auto">Mac:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="GOARCH=&quot;amd64&quot;
GOBIN=&quot;&quot;
GOEXE=&quot;&quot;
GOHOSTARCH=&quot;amd64&quot;
GOHOSTOS=&quot;darwin&quot;
GOOS=&quot;darwin&quot;
GOPATH=&quot;/Users/bobbyz/projects/community/go:/Users/bobbyz/projects/bztech/go:/Users/bobbyz/projects/bobbyz/go&quot;
GORACE=&quot;&quot;
GOROOT=&quot;/usr/local/go&quot;
GOTOOLDIR=&quot;/usr/local/go/pkg/tool/darwin_amd64&quot;
GO15VENDOREXPERIMENT=&quot;1&quot;
CC=&quot;clang&quot;
GOGCCFLAGS=&quot;-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common&quot;
CXX=&quot;clang++&quot;
CGO_ENABLED=&quot;1&quot;"><pre class="notranslate"><code class="notranslate">GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bobbyz/projects/community/go:/Users/bobbyz/projects/bztech/go:/Users/bobbyz/projects/bobbyz/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
</code></pre></div>
<p dir="auto">Linux:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="GOARCH=&quot;amd64&quot;
GOBIN=&quot;&quot;
GOEXE=&quot;&quot;
GOHOSTARCH=&quot;amd64&quot;
GOHOSTOS=&quot;linux&quot;
GOOS=&quot;linux&quot;
GOPATH=&quot;/home/bobbyz/gopath/&quot;
GORACE=&quot;&quot;
GOROOT=&quot;/usr/local/go&quot;
GOTOOLDIR=&quot;/usr/local/go/pkg/tool/linux_amd64&quot;
GO15VENDOREXPERIMENT=&quot;1&quot;
CC=&quot;gcc&quot;
GOGCCFLAGS=&quot;-fPIC -m64 -pthread -fmessage-length=0&quot;
CXX=&quot;g++&quot;
CGO_ENABLED=&quot;1&quot;"><pre class="notranslate"><code class="notranslate">GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bobbyz/gopath/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
</code></pre></div>
<h3 dir="auto">What did you do?</h3>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// This is an exact, unaltered copy-paste of the code I'm running.  I trimmed my live code
// down to just this function body in order to test/reproduce
func (l *logger) close(timeout time.Duration) error {
    fmt.Println(&quot;before select&quot;)
    select {
    case &lt;-time.After(time.Second):
        fmt.Println(&quot;timeout occurred&quot;)
        return errors.New(&quot;timeout&quot;)
    }
}"><pre class="notranslate"><span class="pl-c">// This is an exact, unaltered copy-paste of the code I'm running.  I trimmed my live code</span>
<span class="pl-c">// down to just this function body in order to test/reproduce</span>
<span class="pl-k">func</span> (<span class="pl-s1">l</span> <span class="pl-c1">*</span><span class="pl-smi">logger</span>) <span class="pl-en">close</span>(<span class="pl-s1">timeout</span> time.<span class="pl-smi">Duration</span>) <span class="pl-smi">error</span> {
    <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s">"before select"</span>)
    <span class="pl-k">select</span> {
    <span class="pl-k">case</span> <span class="pl-c1">&lt;-</span><span class="pl-s1">time</span>.<span class="pl-en">After</span>(<span class="pl-s1">time</span>.<span class="pl-c1">Second</span>):
        <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s">"timeout occurred"</span>)
        <span class="pl-k">return</span> <span class="pl-s1">errors</span>.<span class="pl-en">New</span>(<span class="pl-s">"timeout"</span>)
    }
}</pre></div>
<h3 dir="auto">What did you expect to see?</h3>
<p dir="auto">I should see "before select" printed.  Then after 1 second, I should see "timeout occurred" printed.</p>
<h3 dir="auto">What did you see instead?</h3>
<p dir="auto">I see "before select" printed.  Nothing else prints and the program never exits.  This is definitely the only function in my code that prints "before select", so the close method is called, but the channel read from the time.After channel never happens.  I've noticed the program spins my CPU at 100% while I'm waiting for the timeout that never occurs.</p>
<h3 dir="auto">Other</h3>
<p dir="auto">I can only reproduce this when I add a panic() to one of my functions and recover from the panic.  The "close" method shown above runs on program termination, after the panic recovery.  If I modify the panicking code to return nil in place of the panic, I can't reproduce.  That portion of code is outside of this close method.  I also can't reproduce if I remove the select and read directly from the channel.</p>
<p dir="auto">I ripped apart my code trying to find the cause of the hanging select.  I uploaded a functioning but mangled/stripped copy of the code to <a href="https://github.com/bobziuchkovski/golang-select-repro">https://github.com/bobziuchkovski/golang-select-repro</a>.  The code itself hardly makes sense anymore, but it runs and reproduces the hanging select about 1 in 8 times on my laptop.</p>
<p dir="auto">The select in question is in logger.go on line 110.  The panic is triggered in main.go on line 45.  If I comment-out that panic, I can't reproduce the hanging select.  The close method with the select in question is triggered indirectly via line 40 of main.go</p>
<p dir="auto">The plan9/mksysnum_plan9.sh script has a duplicated, mangled copyright header:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file."><pre class="notranslate"><code class="notranslate"># Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
</code></pre></div>