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 <ian.campbell@docker.com>
This commit is contained in:
Ian Campbell 2016-04-07 17:40:41 +01:00
parent 057fb53a6a
commit 54e31f7495

View File

@ -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)
}
}()