mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-28 08:01:04 +00:00
vsock: close incoming UDS conns if we aren't ready
It's possible to receive an incoming UDS connection before the VMM has contacted us to initialize the vrings. In this case, close the incoming connection so the client is aware of we aren't yet ready, and to avoid having a lingering incomplete connection around. Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
parent
b2fa8d91dd
commit
9e8a4efdb9
@ -181,10 +181,9 @@ impl VhostUserVsockThread {
|
||||
fn handle_event(&mut self, fd: RawFd, evset: epoll::Events) {
|
||||
if fd == self.host_sock {
|
||||
// This is a new connection initiated by an application running on the host
|
||||
self.host_listener
|
||||
.accept()
|
||||
.map_err(Error::UnixAccept)
|
||||
.and_then(|(stream, _)| {
|
||||
let conn = self.host_listener.accept().map_err(Error::UnixAccept);
|
||||
if self.mem.is_some() {
|
||||
conn.and_then(|(stream, _)| {
|
||||
stream
|
||||
.set_nonblocking(true)
|
||||
.map(|_| stream)
|
||||
@ -194,6 +193,13 @@ impl VhostUserVsockThread {
|
||||
.unwrap_or_else(|err| {
|
||||
warn!("Unable to accept new local connection: {:?}", err);
|
||||
});
|
||||
} else {
|
||||
// If we aren't ready to process requests, accept and immediately close
|
||||
// the connection.
|
||||
conn.map(drop).unwrap_or_else(|err| {
|
||||
warn!("Error closing an incoming connection: {:?}", err);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Check if the stream represented by fd has already established a
|
||||
// connection with the application running in the guest
|
||||
|
||||
Loading…
Reference in New Issue
Block a user