tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
220 stars 32 forks source link

Long-lived client object can cause "invalid baton" errors #119

Open penberg opened 10 months ago

penberg commented 10 months ago

If you have a long-lived client object, the server can start complaining about the baton:

 LibsqlError: SERVER_ERROR: Server returned HTTP status 400: Received an invalid baton
    at (node_modules/@libsql/client/lib-esm/hrana.js:257:15)
    at (node_modules/@libsql/client/lib-esm/hrana.js:182:36)
    at (node_modules/@libsql/client/lib-esm/hrana.js:184:12)
    at (node_modules/drizzle-orm/libsql/index.mjs:38:12)
    at (node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:210:36) {
  code: 'SERVER_ERROR',
  rawCode: undefined,
  name: 'LibsqlError'
}
txuanson commented 7 months ago

Any update on this?

yotam-haran commented 5 months ago

Hey there! I am using Turso with Drizzle on my backend, and have been running into this error quite frequently today...

This happened with my server, but also during migrations, where the connection is very short-lived. It seems that this is an issue specifically with transactions - I suspect Drizzle's migrations use transactions, and so do some parts of my backend. I haven't been having any issues with operations outside of a transaction.

Is there any plan to address this?

statusunknown418 commented 5 months ago

updates here? it seems to only happen sometimes

garrettApproachableGeek commented 5 months ago

We are seeing this error in production about every 2 days. We don't have long lived clients as each GCP Cloud Function creates it's own client. We are using a transaction in the section of code that throws LibsqlError: SERVER_ERROR: Server returned HTTP status 400: Received an invalid baton.

@libsql/client version 0.5.6

const transaction = await client.transaction('write');
await transaction.execute({
   sql: 'INSERT INTO secret(key, value) VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=? WHERE key=?',
   args: [key, value, value, key]
});
await transaction.commit();
rbestardpino commented 2 months ago

Hey all. It is still happening on version 0.6.2. Did someone figure out a workaround? Not using transactions is not a real solution

Fryuni commented 2 months ago

Happens for every transaction from Vercel in our case

luiz-gustavo-agostinho commented 2 months ago

Running on Laravel with Turso

php artisan migrate:fresh --seed

causes this error to happen after a while. Any solutions?

HTTP request returned status code 400:
Received an invalid baton
 (Connection: turso, SQL: insert into "human_names" ("name", "type", "gender", "updated_at", "created_at") values (Grant, last_name, male, 2024-07-04 19:37:16, 2024-07-04 19:37:16))
PrinceBaghel258025 commented 3 weeks ago

Happens for many transaction when using libsql_experimental