From dad42c8dc40d1b90fff6a47d00d8237f57d161b5 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 7 Apr 2016 17:40:41 +0100 Subject: [PATCH] vsudd: Close via the File vsock not the raw fd. Otherwise the underlying gets closed twice, once by the File's finalizer (which occurs at whichever point vsock appears no longer used) and another time by the syscall.Close(), which leads to EBADF. The various syscall.shutdown can also suffer from this if the File happens to get finalized first, but the reference in the defer'd function now keeps the File alive until we are truly done with the socket. This seems to resolve the random stalls and failures seen in "make test". Signed-off-by: Ian Campbell --- alpine/packages/vsudd/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/alpine/packages/vsudd/main.go b/alpine/packages/vsudd/main.go index 75b22a45a..1dc535fa1 100644 --- a/alpine/packages/vsudd/main.go +++ b/alpine/packages/vsudd/main.go @@ -107,9 +107,9 @@ func handleOne(connid int, fd int, cid, port uint) { log.Printf("%d Accepted connection on fd %d from %08x.%08x", connid, fd, cid, port) defer func() { - log.Println(connid, "Closing vsock", fd) - if err := syscall.Close(fd) ; err != nil { - log.Println(connid, "Error closing", fd ":", err) + log.Println(connid, "Closing vsock", vsock) + if err := vsock.Close() ; err != nil { + log.Println(connid, "Error closing", vsock, ":", err) } }()