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

send all pending responses before shutting down #228

Merged
merged 1 commit into from
May 11, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/asynchronous/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,14 @@ impl Builder for ServerBuilder {
server_shutdown: self.shutdown_waiter.clone(),
handler_shutdown: disconnect_notifier,
},
ServerWriter { rx },
ServerWriter { rx, _server_shutdown: self.shutdown_waiter.clone() },
)
}
}

struct ServerWriter {
rx: MessageReceiver,
_server_shutdown: shutdown::Waiter
Copy link
Collaborator

@wllenyj wllenyj May 10, 2024

Choose a reason for hiding this comment

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

don't need to call wait in exit?
Sorry I forget the details.

Copy link
Contributor Author

@alex-matei alex-matei May 10, 2024

Choose a reason for hiding this comment

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

There is no need for that, the _server_shutdown waiter acts as a barrier for the shutdown.wait_all_exit() call found here:

pub async fn disconnect(&mut self) {
self.shutdown.shutdown();
self.shutdown
.wait_all_exit()
.await
.map_err(|e| {
trace!("wait connection exit error: {}", e);
})
.ok();
trace!("wait connection exit.");
}

When the ServerWriter goes out of scope here, after sending all replies, the _server_shutdown waiter is dropped. When that happens the server shutdown notifier will return from the wait_all_exit() call.

}

#[async_trait]
Expand Down
Loading