Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix worker are notified to stop with non_graceful shutdown #333

Merged
merged 6 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we code this as try_current ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we still expect system when running a server so I think it's fine here.
We can change when actix-rt is made optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I have no idea is why there is 300 ms delay.

}
});
}
ServerCommand::WorkerFaulted(idx) => {
let mut found = false;
Expand Down