vmm: prevent serial manager TCP shutdown deadlock#172
Conversation
| pty_write_out: Option<Arc<AtomicBool>>, | ||
| socket_path: Option<PathBuf>, | ||
| /// Tracks the active TCP client so `Drop` can shut it down before joining. | ||
| active_tcp_stream: Arc<Mutex<Option<TcpStream>>>, |
There was a problem hiding this comment.
I think this should be Option<Arc<Mutex<TcpStream>>>. I'm unsure if you need the Arc<Mutex> at all since you seem to have &mut self available on every call site. Would Option<TcpStream> also work?
There was a problem hiding this comment.
The variable is shared between the main VMM thread and serial-manager thread, so I think we need at least the Arc, and I'd like to synchronize the access to it, thus the Mutex
There was a problem hiding this comment.
and I'd like to synchronize the access to it, thus the Mutex
Never use a Mutex because you'd like to synchronize access - the compiler either forces you or doesn't complain which means there are no unsynchronized accesses :)
But I assume you wanted to say that Rust complains without Arc<Mutex<>>, hence the Mutex is necessary?
There was a problem hiding this comment.
I just tried to remove the Mutex<> part, but yes the compiler complains without it.
|
AI comment:
|
phip1611
left a comment
There was a problem hiding this comment.
Code-wise LGTM but what about Thomas' comment?
Keep track of the active TCP console client so the serial manager can shut it down before waiting for the worker thread to exit. This prevents a shutdown deadlock where a blocked TCP read keeps VM teardown stuck after migration or console disconnects. By storing a clone of the active TCP stream and closing it during drop, the read side is forced to wake up and observe the shutdown path instead of waiting forever in the socket read. The worker then exits its epoll loop, the join returns, and VM teardown can finish. On-behalf-of: SAP sebastian.eydam@sap.com Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
fe7f1e3 to
2d7ec1c
Compare
Oh wtf that was a rebasing mistake I think. I tried making the socket nonblocking first, but then decided that the current solution seems easier and more reliable. I reverted this change. |
phip1611
left a comment
There was a problem hiding this comment.
After offline discussion. LGTM.
Keep track of the active TCP console client so the serial manager can shut it down before waiting for the worker thread to exit. This prevents a shutdown deadlock where a blocked TCP read keeps VM teardown stuck after migration or console disconnects.
By storing a clone of the active TCP stream and closing it during drop, the read side is forced to wake up and observe the shutdown path instead of waiting forever in the socket read. The worker then exits its epoll loop, the join returns, and VM teardown can finish.