Skip to content

Commit

Permalink
Fix worker are notified to stop with non_graceful shutdown (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Apr 15, 2021
1 parent 47fba25 commit aeb81ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
4 changes: 4 additions & 0 deletions actix-server/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changes

## Unreleased - 2021-xx-xx
* Server shutdown would notify all workers to exit regardless if shutdown is graceful.
This would make all worker shutdown immediately in force shutdown case. [#333]

[#333]: https://github.com/actix/actix-net/pull/333


## 2.0.0-beta.4 - 2021-04-01
Expand Down
48 changes: 16 additions & 32 deletions actix-server/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,45 +381,29 @@ impl ServerBuilder {
let notify = std::mem::take(&mut self.notify);

// stop workers
if !self.handles.is_empty() && graceful {
let iter = self
.handles
.iter()
.map(move |worker| worker.1.stop(graceful))
.collect();

let fut = join_all(iter);

rt::spawn(async move {
let _ = fut.await;
if let Some(tx) = completion {
let _ = tx.send(());
}
for tx in notify {
let _ = tx.send(());
}
if exit {
rt::spawn(async {
sleep(Duration::from_millis(300)).await;
System::current().stop();
});
}
});
} else {
// we need to stop system if server was spawned
if self.exit {
rt::spawn(async {
sleep(Duration::from_millis(300)).await;
System::current().stop();
});
let stop = self
.handles
.iter()
.map(move |worker| worker.1.stop(graceful))
.collect();

rt::spawn(async move {
if graceful {
let _ = join_all(stop).await;
}

if let Some(tx) = completion {
let _ = tx.send(());
}
for tx in notify {
let _ = tx.send(());
}
}

if exit {
sleep(Duration::from_millis(300)).await;
System::current().stop();
}
});
}
ServerCommand::WorkerFaulted(idx) => {
let mut found = false;
Expand Down

0 comments on commit aeb81ad

Please sign in to comment.