dragonball: fix EPOLLHUP/EPOLLERR events handling in vsock

1. EPOLLHUP events also need to be read and will be got len 0.
2. We should kill the connection when EPOLLERR events are received.

Signed-off-by: Tim Zhang <tim@hyper.sh>
Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
Tim Zhang 2024-04-16 20:09:57 +08:00
parent 7b11fd2546
commit 221c5b51fe

View File

@ -460,7 +460,8 @@ impl VsockEpollListener for VsockConnection {
/// Notify the connection about an event (or set of events) that it was /// Notify the connection about an event (or set of events) that it was
/// interested in. /// interested in.
fn notify(&mut self, evset: epoll::Events) { fn notify(&mut self, evset: epoll::Events) {
if evset.contains(epoll::Events::EPOLLIN) { // EPOLLHUP also needs to be read and will be got len 0
if evset.contains(epoll::Events::EPOLLIN) || evset.contains(epoll::Events::EPOLLHUP) {
// Data can be read from the host stream. Setting a Rw pending // Data can be read from the host stream. Setting a Rw pending
// indication, so that the muxer will know to call `recv_pkt()` // indication, so that the muxer will know to call `recv_pkt()`
// later. // later.
@ -514,6 +515,19 @@ impl VsockEpollListener for VsockConnection {
self.pending_rx.insert(PendingRx::CreditUpdate); self.pending_rx.insert(PendingRx::CreditUpdate);
} }
} }
// The host stream has encountered an error. We'll kill this
// connection.
if evset.contains(epoll::Events::EPOLLERR)
&& !evset.contains(epoll::Events::EPOLLIN)
&& !evset.contains(epoll::Events::EPOLLOUT)
{
warn!(
"vsock: connection received EPOLLERR event: lp={}, pp={}",
self.local_port, self.peer_port
);
self.kill();
}
} }
} }