From 26a6d5670fb1f78f0d5dd200c1a5aa4f75bf23d1 Mon Sep 17 00:00:00 2001 From: Roman Shanin Date: Mon, 13 Jan 2025 16:45:04 +0700 Subject: [PATCH] fix(network/worker): forget response token to prevent recursion on drop --- elfo-network/src/worker/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/elfo-network/src/worker/mod.rs b/elfo-network/src/worker/mod.rs index 55986fd..9c536bd 100644 --- a/elfo-network/src/worker/mod.rs +++ b/elfo-network/src/worker/mod.rs @@ -891,19 +891,26 @@ impl remote::RemoteHandle for RemoteHandle { let recipient = NetworkAddr::from_remote(token.sender()); + let mut item = Some(KanalItem { + recipient, + envelope, + token: Some(token), + }); + if likely(self.tx_flows.do_acquire(recipient)) { - let item = KanalItem { - recipient, - envelope, - token: Some(token), - }; - match self.tx.try_send(item) { + match self.tx.try_send_option(&mut item) { Ok(true) => return, Ok(false) => unreachable!(), Err(_) => {} } } + if let Some(item) = item { + let token = item.token.expect("response token set above"); + // Flow is closed, token is not required anymore + token.forget(); + } + trace!(addr = %recipient, "flow is closed, response is lost"); } }