diff --git a/crates/voelin-core/src/link/tests.rs b/crates/voelin-core/src/link/tests.rs index 9d37375..ab1bf27 100644 --- a/crates/voelin-core/src/link/tests.rs +++ b/crates/voelin-core/src/link/tests.rs @@ -1308,6 +1308,21 @@ async fn a_session_closes_as_the_table_says() { assert!(matches!(error, SessionError::Closed(_)), "{error:?}"); } +/// A session made through the plain `Connector` interface, outside an engine +/// (the conformance suite does, so does any client of the seam that is no +/// engine), has no engine to hold the account watches the link listens to: +/// the session keeps their senders for as long as it runs. The link ends its +/// connection with "account source closed" when it has lost them. +#[tokio::test(flavor = "multi_thread")] +async fn a_session_made_outside_an_engine_keeps_the_watches_of_its_link_open() { + let (session, _pushes, inner) = open(everything()).await; + // Let the driver start, and the connect that returned drop what it held. + tokio::time::sleep(Duration::from_millis(50)).await; + assert!(inner.ctx.myts_identity.has_changed().is_ok(), "the identity watch lost its sender"); + assert!(inner.ctx.myts_data.has_changed().is_ok(), "the data watch lost its sender"); + drop(session); +} + #[tokio::test(flavor = "multi_thread")] async fn a_connect_that_the_link_fails_is_an_error_with_its_reason() { let (conns, mut seen) = mpsc::unbounded_channel(); diff --git a/crates/voelin-core/src/ts_session/mod.rs b/crates/voelin-core/src/ts_session/mod.rs index da67c7f..9558a50 100644 --- a/crates/voelin-core/src/ts_session/mod.rs +++ b/crates/voelin-core/src/ts_session/mod.rs @@ -703,7 +703,14 @@ async fn connect_link( closed: closed_rx, own_slot, }; - tokio::spawn(driver.run(cmds_rx)); + tokio::spawn(async move { + driver.run(cmds_rx).await; + // The context keeps the senders of the account watches that a connection + // made outside an engine has (`LocalCtx::standalone`): the link ends its + // connection when a watch has no sender, so the context lives as long as + // the session does. + drop(ctx); + }); Ok(LocalConnected { connected: Connected { session: Arc::new(session),