Skip to content

Commit aeb81ad

Browse files
authored
Fix worker are notified to stop with non_graceful shutdown (#333)
1 parent 47fba25 commit aeb81ad

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

actix-server/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changes
22

33
## Unreleased - 2021-xx-xx
4+
* Server shutdown would notify all workers to exit regardless if shutdown is graceful.
5+
This would make all worker shutdown immediately in force shutdown case. [#333]
6+
7+
[#333]: https://github.com/actix/actix-net/pull/333
48

59

610
## 2.0.0-beta.4 - 2021-04-01

actix-server/src/builder.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -381,45 +381,29 @@ impl ServerBuilder {
381381
let notify = std::mem::take(&mut self.notify);
382382

383383
// stop workers
384-
if !self.handles.is_empty() && graceful {
385-
let iter = self
386-
.handles
387-
.iter()
388-
.map(move |worker| worker.1.stop(graceful))
389-
.collect();
390-
391-
let fut = join_all(iter);
392-
393-
rt::spawn(async move {
394-
let _ = fut.await;
395-
if let Some(tx) = completion {
396-
let _ = tx.send(());
397-
}
398-
for tx in notify {
399-
let _ = tx.send(());
400-
}
401-
if exit {
402-
rt::spawn(async {
403-
sleep(Duration::from_millis(300)).await;
404-
System::current().stop();
405-
});
406-
}
407-
});
408-
} else {
409-
// we need to stop system if server was spawned
410-
if self.exit {
411-
rt::spawn(async {
412-
sleep(Duration::from_millis(300)).await;
413-
System::current().stop();
414-
});
384+
let stop = self
385+
.handles
386+
.iter()
387+
.map(move |worker| worker.1.stop(graceful))
388+
.collect();
389+
390+
rt::spawn(async move {
391+
if graceful {
392+
let _ = join_all(stop).await;
415393
}
394+
416395
if let Some(tx) = completion {
417396
let _ = tx.send(());
418397
}
419398
for tx in notify {
420399
let _ = tx.send(());
421400
}
422-
}
401+
402+
if exit {
403+
sleep(Duration::from_millis(300)).await;
404+
System::current().stop();
405+
}
406+
});
423407
}
424408
ServerCommand::WorkerFaulted(idx) => {
425409
let mut found = false;

0 commit comments

Comments
 (0)