sqld icon indicating copy to clipboard operation
sqld copied to clipboard

Database starts returning HTTP status 500 after lots of inserts

Open penberg opened this issue 2 years ago • 1 comments

I have two reports of the database starting to return HTTP status 500 after lots of inserts. One user reported that dropping the tables, creating them again and inserting the data fixed the issue, which suggest that the issue does not always happen when inserting lots of data.

penberg avatar Oct 01 '23 06:10 penberg

Oh so I'm not crazy and doing bad things on my side... lots of inserts in my case is usually > 100 :sweat_smile: dunno if that's a lot :grin:

simple dirty local code:

use libsql_client;

#[tokio::main]
async fn main() {
    let db = libsql_client::Client::from_env().await.unwrap();
    let _ = db.execute("drop table if exists example_users;").await.unwrap();
    let _ = db.execute("create table if not exists example_users (uid text primary key, email text);").await.unwrap();
    let rs = db.execute("select count(*) from example_users;").await.unwrap();
    println!("result {:?}", rs);
    for n in 0..150 {
        let stmt = format!("insert into example_users values ('uid {n}', 'email {n}');");
        // println!(". {}", stmt);
        let _ = db.execute(stmt).await;
    }
    let rs = db.execute("select count(*) from example_users;").await.unwrap();
    println!("result {:?}", rs);
}

will produce:

$ LIBSQL_CLIENT_URL=http://127.0.0.1:8080 cargo run
result ResultSet { columns: ["count (*)"], rows: [Row { values: [Integer { value: 0 }], value_map: {"count (*)": Integer { value: 0 }} }], rows_affected: 0, last_insert_rowid: None }
result ResultSet { columns: ["count (*)"], rows: [Row { values: [Integer { value: 140 }], value_map: {"count (*)": Integer { value: 140 }} }], rows_affected: 0, last_insert_rowid: None }

10 missing rows :(

sqld running (fresh build) and erroring:

config:
	- mode: standalone
	- database path: data.sqld
	- extensions path: <disabled>
	- listening for HTTP requests on: 127.0.0.1:8080
	- grpc_tls: no
2023-10-16T13:44:02.709804Z  INFO sqld: listening for incoming user HTTP connection on 127.0.0.1:8080
2023-10-16T13:44:02.709848Z  INFO sqld: listening for incoming user hrana websocket connection on 0.0.0.0:7001
2023-10-16T13:44:02.709987Z  WARN sqld: No server heartbeat configured
2023-10-16T13:44:02.710183Z  WARN sqld::config: No authentication specified, the server will not require authentication
2023-10-16T13:44:03.248358Z  INFO sqld::replication::primary::logger: SQLite autocheckpoint: 1000
2023-10-16T13:44:03.250278Z  INFO sqld::namespace: loaded namespace: `default`
2023-10-16T13:44:17.345807Z ERROR sqld::hrana::http: hrana server: Timed out while openning database connection
2023-10-16T13:44:17.345844Z ERROR sqld::error: HTTP API: 500 Internal Server Error, {"error":"Internal Error: `Timed out while openning database connection`"}
2023-10-16T13:44:17.345871Z ERROR tower_http::trace::on_failure: response failed classification=Status code: 500 Internal Server Error latency=1000 ms

ultrabug avatar Oct 16 '23 13:10 ultrabug