tursodatabase/libsql

The stream has expired due to inactivity

wyhaya opened this issue · 8 comments

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.

What is the duration/driver for making the queries? If its an http request, I would create a connection per http request that comes in. If you are sleeping I would do the same thing, if you need to run a bunch of sql requests one right after another then re-use the connection.

I'm having the same issue, but with https://github.com/libsql/go-libsql.

Thank you for the suggestion, @LucioFranco, this issue has been resolved.

Is there any other workaround for this? I have the same issue when hosting my db locally with turso dev. This issue does not occur when I replace Turso libsql driver with a sqlite3 driver while keeping the same .db file.

I'm having the same issue, but with https://github.com/libsql/go-libsql.

This should already be fixed in Go

Same issue in Python libsql.

I am experiencing this issue with 'go' also. I am using https://github.com/tursodatabase/libsql

+1 typescript