From 6bc38f39b3caa4867106cd2c556e3244b7267779 Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Thu, 12 Jun 2014 04:37:00 -0400 Subject: [PATCH] Be more strict about file closing in bind This eliminates the race condition mentioned in a54c913a by forbidding duplicate binds to the same socket (well, at least in the sense that attempting to do so will *always* result in an error instead of nondeterministically resulting in an error). --- bind/bind.go | 1 + bind/einhorn.go | 1 + 2 files changed, 2 insertions(+) diff --git a/bind/bind.go b/bind/bind.go index 3ddf3e6..b8ff22a 100644 --- a/bind/bind.go +++ b/bind/bind.go @@ -75,6 +75,7 @@ func listenTo(bind string) (net.Listener, error) { bind, err) } f := os.NewFile(uintptr(fd), bind) + defer f.Close() return net.FileListener(f) } else if strings.HasPrefix(bind, "einhorn@") { fd, err := strconv.Atoi(bind[8:]) diff --git a/bind/einhorn.go b/bind/einhorn.go index 8c11c75..c61e322 100644 --- a/bind/einhorn.go +++ b/bind/einhorn.go @@ -65,6 +65,7 @@ func einhornBind(n int) (net.Listener, error) { fno := einhornFdMap(n) f := os.NewFile(uintptr(fno), fmt.Sprintf("einhorn@%d", n)) + defer f.Close() return net.FileListener(f) }