Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR libsql::replication: replicator sync | database disk image is malformed #1607

Open
Aft1n opened this issue Jul 25, 2024 · 13 comments
Open
Labels
bug Something isn't working embedded replicas

Comments

@Aft1n
Copy link

Aft1n commented Jul 25, 2024

I have an app deployed in production that has a replica db saved in the app folder, and today i checked the logs and saw this error:

ERROR libsql::replication: replicator sync error: replication error: Injector error: SQLite error: database disk image is malformed

Everything was working perfectly fine for couple of weeks, no changes to db schema were made, it just simply started to show this error in logs

@Aft1n
Copy link
Author

Aft1n commented Jul 25, 2024

Somehow my replica db got corrupted, after resyncing replica db locally and pushing it back to the server it got fixed.. What could have caused the problem?? Multiple user writes or something else?

@haaawk
Copy link
Contributor

haaawk commented Jul 25, 2024

Sometimes embedded replicas get corrupted when their db file is opened with regular sqlite3 driver. Maybe you did something like that?

@LucioFranco Would you be able to help please?

@Aft1n
Copy link
Author

Aft1n commented Jul 25, 2024

Considering this file was deployed in production, i didn't touch it. Though i had some active traffic to the website before noticing this error, though it was mostly reads, and at first i thought that it was some kind of attack, like sql injection( im not very proficient in those issues)

But could multiple simultaneous writes and potential error corrupt it??

@haaawk
Copy link
Contributor

haaawk commented Jul 25, 2024

It is not possible to write directly to embedded replicas. The writes are being forwarded to a primary in the cloud and then fetched back with sync. So multiple writers should be fine I think

@Aft1n
Copy link
Author

Aft1n commented Jul 25, 2024

Yeah, i know that. But if there was some race condition or some errors during writes, maybe this could potentially on sync corrupt replica dbs. Interesting thing was, that i have a full-stack app that has replica. And also a separate api that also has its own replica. And even though some actions were happening on the full-stack app, inside my api application DB was corrupted as well..

So basically there was something going on in turso parent db, and this error was synced to both replicas. But it worked totally fine with turso dashboard, and after deleting replicas and syncing again it got fixed.

@haaawk
Copy link
Contributor

haaawk commented Jul 26, 2024

@LucioFranco I think you should investigate that as part of your embedded replicas work

@penberg penberg added bug Something isn't working embedded replicas labels Jul 26, 2024
@LucioFranco
Copy link
Contributor

@Aft1n could you share the version of libsql that you were using?

@Aft1n
Copy link
Author

Aft1n commented Jul 29, 2024

i was using the latest - 7.0

@LucioFranco
Copy link
Contributor

I think your theory sounds correct, I would say if you start to see this issue again you can ping me on discord and I can take a look at what is going on it. This is slightly hard to debug since the malformed error is quite cryptic.

@Aft1n
Copy link
Author

Aft1n commented Aug 2, 2024

So this error happened again, heres an abrupt error from logs:

22:56:11 1|main | error: replication error: Injector error: SQLite error: database disk image is malformed
22:56:11 1|main | at new Database (/app/node_modules/libsql/index.js:75:17)
22:56:11 1|main | at _createClient (/app/node_modules/@libsql/client/lib-esm/sqlite3.js:39:16)
22:56:11 1|main | at /app/src/db/index.ts:7:28
22:56:11 1|main | Bun v1.1.9 (Linux x64)

22:54:47 1|main | 2024-08-02T22:54:47.369381Z ERROR libsql::replication: replicator sync error: replication error: Injector error: SQLite error: database disk image is malformed
22:54:47 0|main | 2024-08-02T22:54:47.376994Z ERROR libsql::replication: replicator sync error: replication error: Injector error: SQLite error: database disk image is malformed

And i have noticed that my Turso sync usage skyrocketed, because it was having an error and couldnt go through, possibly its currently 5gb/2gb

@Aft1n
Copy link
Author

Aft1n commented Aug 2, 2024

As well as found this one in my fullstack app, that basically is the source for all changes to be sent to turso from.. And this a cron task that failed i assume, or something happend to close the connection. Maybe this could affect it?

error logs

@vanillacode314
Copy link

having the same issue with a deployement on railway

@LucioFranco
Copy link
Contributor

@Aft1n @vanillacode314 are either of you still experiencing this issue? If so could you try to give me a small example of how you're able to trigger it. Unfortunately, just the error message is not very helpful and doesn't really tell us why it was malformed and I am unable to reproduce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working embedded replicas
Projects
None yet
Development

No branches or pull requests

5 participants