From b8632b4034327592235f0325028133702649cc94 Mon Sep 17 00:00:00 2001 From: Zixuan Tan Date: Wed, 4 Oct 2023 16:39:14 +0800 Subject: [PATCH] dragonball: vsock: properly handle EPOLLHUP/EPOLLERR events When one end of the connection close, the epoll event will be triggered forever. We should close the connection and kill the connection. Fixes: #6714 Signed-off-by: Zixuan Tan --- .../src/vsock/csm/connection.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs b/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs index e2ca7e3339..c3415cf6cb 100644 --- a/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs +++ b/src/dragonball/src/dbs_virtio_devices/src/vsock/csm/connection.rs @@ -487,6 +487,31 @@ impl VsockEpollListener for VsockConnection { self.pending_rx.insert(PendingRx::CreditUpdate); } } + + if evset.contains(epoll::Events::EPOLLHUP) + && !evset.contains(epoll::Events::EPOLLIN) + && !evset.contains(epoll::Events::EPOLLOUT) + { + // The host stream has been hung up. We'll kill this connection. + warn!( + "vsock: connection received EPOLLHUP event: lp={}, pp={}", + self.local_port, self.peer_port + ); + self.kill(); + } + + if evset.contains(epoll::Events::EPOLLERR) + && !evset.contains(epoll::Events::EPOLLIN) + && !evset.contains(epoll::Events::EPOLLOUT) + { + // The host stream has encountered an error. We'll kill this + // connection. + warn!( + "vsock: connection received EPOLLERR event: lp={}, pp={}", + self.local_port, self.peer_port + ); + self.kill(); + } } }