close channel early on drop of ServerWorker

This commit is contained in:
fakeshadow 2021-04-13 10:13:03 +08:00
parent 39fc6569a7
commit 76d3e8ee75
2 changed files with 9 additions and 1 deletions

View File

@ -135,6 +135,13 @@ pub(crate) struct ServerWorker {
shutdown_timeout: Duration,
}
/// Set worker to unavailable when dropping.
impl Drop for ServerWorker {
fn drop(&mut self) {
self.rx.close();
}
}
struct WorkerService {
factory: usize,
status: WorkerServiceStatus,

View File

@ -517,6 +517,8 @@ async fn worker_restart() {
let (server, sys) = rx.recv().unwrap();
sleep(Duration::from_secs(3)).await;
let mut buf = [0; 8];
// worker 1 would not restart and return it's id consistently.
@ -545,7 +547,6 @@ async fn worker_restart() {
// worker 2 restarting and work goes to worker 1.
let mut stream = TcpStream::connect(addr).await.unwrap();
let n = stream.read(&mut buf).await.unwrap();
let id = String::from_utf8_lossy(&buf[0..n]);
assert_eq!("1", id);