diff --git a/libsql/src/hrana/stream.rs b/libsql/src/hrana/stream.rs index c63f600c75..da606a198d 100644 --- a/libsql/src/hrana/stream.rs +++ b/libsql/src/hrana/stream.rs @@ -176,7 +176,7 @@ where pub async fn cursor(&self, batch: Batch) -> Result> { let mut client = self.inner.stream.lock().await; - let cursor = client.open_cursor(batch).await?; + let cursor = client.open_cursor(batch, !self.is_autocommit()).await?; Ok(cursor) } @@ -314,7 +314,7 @@ where Ok(resp) } - pub async fn open_cursor(&mut self, batch: Batch) -> Result> { + pub async fn open_cursor(&mut self, batch: Batch, use_baton: bool) -> Result> { let msg = CursorReq { baton: self.baton.clone(), batch, @@ -330,14 +330,14 @@ where self.cursor_url = Arc::from(format!("{base_url}/v3/cursor")); } match response.baton.take() { - None => { - tracing::trace!("client stream has been closed by the server"); - self.reset(); - } // stream has been closed by the server - Some(baton) => { + Some(baton) if use_baton => { tracing::trace!("client stream has been assigned with baton: `{}`", baton); self.baton = Some(baton) } + _ => { + tracing::trace!("client stream has been closed by the server"); + self.reset(); + } } Ok(cursor) }