libsql-client-ts icon indicating copy to clipboard operation
libsql-client-ts copied to clipboard

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

Open penberg opened this issue 2 years ago • 8 comments

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'
}

penberg avatar Oct 25 '23 07:10 penberg

Any update on this?

txuanson avatar Jan 22 '24 01:01 txuanson

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?

yotam-haran avatar Mar 18 '24 20:03 yotam-haran

updates here? it seems to only happen sometimes

statusunknown418 avatar Mar 19 '24 02:03 statusunknown418

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();

garrettApproachableGeek avatar Mar 21 '24 14:03 garrettApproachableGeek

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

rbestardpino avatar Jun 21 '24 22:06 rbestardpino

Happens for every transaction from Vercel in our case

Fryuni avatar Jul 01 '24 03:07 Fryuni

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))

luiz-gustavo-agostinho avatar Jul 04 '24 17:07 luiz-gustavo-agostinho

Happens for many transaction when using libsql_experimental

PrinceBaghel258025 avatar Aug 21 '24 10:08 PrinceBaghel258025