tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
9.54k stars 252 forks source link

The stream expired due to inactivity with SQLC and turso #1670

Open DogAndHerDude opened 1 month ago

DogAndHerDude commented 1 month ago

I'm not sure what I might be doing wrong. Basically if I wait a short while before making first or second connection, I get:

error code = 1: Error executing statement: Hrana: `api error: `{"message":"The stream has expired due to inactivity","code":"STREAM_EXPIRED"}``
2024-08-15T13:47:59.110452Z ERROR libsql_server::hrana::http: hrana server: Stream handle for 15505556566524579603 is expired

I'm running it locally via turso dev --db-file=./dev.db

I'm not sure whether I should be pinging the server before every query? I've tried that, but it seems to not make any difference. Is there a way I should be connecting? I'm using a the most simple way via database/sql in golang. Just a plain ol' conn, err := sql.Open("libsql", "http://...")

The connection is the passed to the sqlc generated function: queries := db.New(conn) which is the passed around by pointer to my services and what not.

Is this the wrong approach or am I missing completely?

Quick edit:

By the looks of it it's only an issue if you're running tuso dev --db-file=.... Obviously, if you just directly point to the file everything is fine, and if you're using the Turso hosted DB it's also fine.

As I understand if you point it to your libsql:/<my-db>.turso.io it also connects via http? Why would it be any different in that case?