diff --git a/examples/beamsh/beamsh.go b/examples/beamsh/beamsh.go index d83fbe7b78..6f889149c2 100644 --- a/examples/beamsh/beamsh.go +++ b/examples/beamsh/beamsh.go @@ -67,8 +67,10 @@ func CmdCat(args []string, f *os.File) { func CmdEcho(args []string, f *os.File) { resp, err := beam.FdConn(int(f.Fd())) if err != nil { + Fatal(err) return } + defer resp.Close() r, w, err := os.Pipe() if err != nil { return diff --git a/unix.go b/unix.go index 7dfff8a1ac..14326ac7da 100644 --- a/unix.go +++ b/unix.go @@ -199,13 +199,14 @@ func USocketPair() (*net.UnixConn, *net.UnixConn, error) { // FdConn wraps a file descriptor in a standard *net.UnixConn object, or // returns an error if the file descriptor does not point to a unix socket. +// This creates a duplicate file descriptor. It's the caller's responsibility +// to close both. func FdConn(fd int) (*net.UnixConn, error) { f := os.NewFile(uintptr(fd), fmt.Sprintf("%d", fd)) conn, err := net.FileConn(f) if err != nil { return nil, err } - f.Close() uconn, ok := conn.(*net.UnixConn) if !ok { conn.Close()