<pre class="notranslate">net.TCPConn embeds net.conn, which has this:

// File sets the underlying os.File to blocking mode and returns a copy.
// It is the caller's responsibility to close f when finished.
// Closing c does not affect f, and closing f does not affect c.
//
// The returned os.File's file descriptor is different from the connection's.
// Attempting to change properties of the original using this duplicate
// may or may not have the desired effect.
func (c *conn) File() (f *os.File, err error) { return c.fd.dup() }

And elsewhere:

func (fd *netFD) dup() (f *os.File, err error) {
    syscall.ForkLock.RLock()
    ns, err := syscall.Dup(fd.sysfd)
    if err != nil {
        syscall.ForkLock.RUnlock()
        return nil, &amp;OpError{"dup", fd.net, fd.laddr, err}
    }
    syscall.CloseOnExec(ns)
    syscall.ForkLock.RUnlock()

    // We want blocking mode for the new fd, hence the double negative.
    // This also puts the old fd into blocking mode, meaning that
    // I/O will block the thread instead of letting us use the epoll server.
    // Everything will still work, just with more threads.
    if err = syscall.SetNonblock(ns, false); err != nil {
        return nil, &amp;OpError{"setnonblock", fd.net, fd.laddr, err}
    }

    return os.NewFile(uintptr(ns), fd.name()), nil
}


However, O_NONBLOCK is a property of the open file, not the fd.
It is shared between all fds referring to the same file, *even
across processes*.

<a href="http://cr.yp.to/unix/nonblock.html" rel="nofollow">http://cr.yp.to/unix/nonblock.html</a>

Hence, this protection does not actually work. To add insult to injury, calling .File()
*actively* screws up the epoll by disabling O_NONBLOCK.

Here's a demonstration that setting O_NONBLOCK on a dup'd socket
affects the duplicates, also at <a href="http://play.golang.org/p/w9Fwqofegp" rel="nofollow">http://play.golang.org/p/w9Fwqofegp</a> though not runnable
in the playground:

package main

import (
    "fmt"
    "syscall"
)

// copy-paste from src/pkg/syscall/zsyscall_linux_amd64.go
func fcntl(fd int, cmd int, arg int) (val int, err error) {
    r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg))
    val = int(r0)
    if e1 != 0 {
        err = e1
    }
    return
}

func isBlocking(fd int) bool {
    val, err := fcntl(fd, syscall.F_GETFL, 0)
    if err != nil {
        panic(err)
    }
    return val&amp;syscall.O_NONBLOCK == 0
}

func main() {
    dupped, err := syscall.Dup(0)
    if err != nil {
        panic(err)
    }
    fmt.Printf("before: stdin is blocking: %v\n", isBlocking(0))
    fmt.Printf("before: dupped is blocking: %v\n", isBlocking(dupped))
    err = syscall.SetNonblock(0, true)
    if err != nil {
        panic(err)
    }
    fmt.Printf("after: stdin is blocking: %v\n", isBlocking(0))
    fmt.Printf("after: dupped is blocking: %v\n", isBlocking(dupped))
}</pre>
<pre class="notranslate"><a href="http://play.golang.org/p/icbjgkx71B" rel="nofollow">http://play.golang.org/p/icbjgkx71B</a>

got:
gc produces the initialization order: c b a .

want:
The variables b and c are independent of each other, and b is declared before c, so the
order should be: b c a .

gccgo reports the order: b c a .

Based on spec clarification <a href="https://golang.org/cl/99020043" rel="nofollow">https://golang.org/cl/99020043</a> (<a href="https://golang.org/issue/6703" rel="nofollow">issue #6703</a>).</pre>