Skip to content

The stream has expired due to inactivity #985

@wyhaya

Description

@wyhaya

Example

#[tokio::main]
async fn main() {
    let db = Database::open_remote("https://...turso.io", "...").unwrap();
    let conn = db.connect().unwrap();

    // Ok
    conn.query("select 0", ()).await.unwrap();

    std::thread::sleep(std::time::Duration::from_secs(15));

    // Err: "{\"message\":\"The stream has expired due to inactivity\",\"code\":\"STREAM_EXPIRED\"}",
    conn.query("select 0", ()).await.unwrap();
}

The application needs to run for a long time, but SQL queries are not called frequently. This error occurs whenever there is a period of inactivity, and it cannot be recovered from. Even if called again, the same result will be obtained.

This is quite common in Web App. What is the best approach (perhaps I missed something)?

  1. Should I call db.connect() to obtain a new connection before each SQL query?
  2. Call ping every few seconds to keep the connection active.
  3. Create a libsql connection pool.

Thanks libSQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions