Skip to content

Commit

Permalink
fix: residual fuse mountpoint after graceful shutdown
Browse files Browse the repository at this point in the history
    1. Case1: Fuse server exits in thread not main. There is possibility
       that process finishes before shutdown of server.
    2. Case2: Fuse server exits in thread of state machine. There is
       possibiltiy that state machine not responses to signal catch
       thread. Then dead lock happens. Process exits before shutdown of
       server.

    This pr aims to seperator shutdown actions from signal catch
    handler. It only notifies controller. Controller exits with
    shutdown of fuse server. No race. No deadlock.

Signed-off-by: 泰友 <[email protected]>
  • Loading branch information
泰友 authored and imeoer committed Jun 18, 2024
1 parent 31899f9 commit 09ba5e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions service/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,16 @@ impl DaemonController {
self.fs_service.lock().unwrap().clone()
}

/// Shutdown all services managed by the controller.
pub fn shutdown(&self) {
/// Notify controller shutdown
pub fn notify_shutdown(&self) {
// Marking exiting state.
self.active.store(false, Ordering::Release);
// Signal the `run_loop()` working thread to exit.
let _ = self.waker.wake();
}

/// Shutdown all services managed by the controller.
pub fn shutdown(&self) {
let daemon = self.daemon.lock().unwrap().take();
if let Some(d) = daemon {
if let Err(e) = d.trigger_stop() {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ mod nbd {
}

extern "C" fn sig_exit(_sig: std::os::raw::c_int) {
DAEMON_CONTROLLER.shutdown();
DAEMON_CONTROLLER.notify_shutdown();
}

fn main() -> Result<()> {
Expand Down

0 comments on commit 09ba5e7

Please sign in to comment.