Skip to content

Commit

Permalink
guarantee SessionActor is dropped before close is handled (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB authored Sep 4, 2024
1 parent 07f0a85 commit 53b447b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## v0.6.4

- Guarantee the internal `SessionActor` is dropped before `ServerExt::on_disconnect` is called.


## v0.6.3

- Allow users to use tokio v2.4.0 in their projects. See [#106](https://github.com/gbaranski/ezsockets/pull/106).
Expand Down
7 changes: 4 additions & 3 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<I: std::fmt::Display + Clone + Send, C: Send> Session<I, C> {
closed_indicator: Arc::new(Mutex::new(Some(closed_receiver))),
};
let session = session_fn(handle.clone());
let mut actor = SessionActor::new(
let actor = SessionActor::new(
session,
session_id,
to_socket_receiver,
Expand All @@ -82,6 +82,7 @@ impl<I: std::fmt::Display + Clone + Send, C: Send> Session<I, C> {
);

tokio::spawn(async move {
// Note: SessionActor::run consumes the actor, guaranteeing it is dropped before the close event is sent.
let result = actor.run().await;
closed_sender.send(result).unwrap_or_default();
});
Expand Down Expand Up @@ -172,7 +173,7 @@ impl<I: std::fmt::Display + Clone, C> Session<I, C> {
}

pub(crate) struct SessionActor<E: SessionExt> {
pub extension: E,
extension: E,
id: E::ID,
to_socket_receiver: mpsc::UnboundedReceiver<InMessage>,
session_call_receiver: mpsc::UnboundedReceiver<E::Call>,
Expand All @@ -196,7 +197,7 @@ impl<E: SessionExt> SessionActor<E> {
}
}

pub(crate) async fn run(&mut self) -> Result<Option<CloseFrame>, Error> {
pub(crate) async fn run(mut self) -> Result<Option<CloseFrame>, Error> {
loop {
tokio::select! {
biased;
Expand Down

0 comments on commit 53b447b

Please sign in to comment.