# sqlite error when attempting to update records with multiple machines

**URL:** <https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837>\
**Category:** General\
**Tags:** machines, sqlite, litefs, login-only\
**Created:** [March 19, 2024, 12:29pm UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837 "2024-03-19T12:29:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![moorst](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/moorst/32/18688_2.png) [@moorst](https://community.fly.io/u/moorst)\
**Post date:** [March 19, 2024, 12:29pm UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/1 "2024-03-19T12:29:36Z")

</div>

I’m regularly seeing the following error come through when I scale beyond one machine:

```auto
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteError { extended_code: 778, message: Some("disk I/O error") }), transient: false })

```

I deployed my remix (epic stack) app following the instructions here: [epic-stack/docs/deployment.md at main · epicweb-dev/epic-stack · GitHub](https://github.com/epicweb-dev/epic-stack/blob/main/docs/deployment.md) and saw no issues.

but after I scaling up to 2 machines (following the instructions here [epic-stack/docs/database.md at main · epicweb-dev/epic-stack · GitHub](https://github.com/epicweb-dev/epic-stack/blob/main/docs/database.md)) I’ve started to see these issues come through and see the same when connecting prisma studio to the primary machine and attempting to update records there.

is there some configuration I’m missing? currently have 2 machines in lhr region (with one of them currently the primary) and another couple in ewr.

any help very much appreciated!

---

<div class="post-metadata">

**Author:** ![mayailurus](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/mayailurus/32/17593_2.png) [@mayailurus](https://community.fly.io/u/mayailurus)\
**Post date:** [March 19, 2024, 10:17pm UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/2 "2024-03-19T22:17:43Z")

</div>

> [@moorst](#):
>
> `disk I/O error`

Hi… Given that it occurs during writes…

> If the local node is not the primary then SQLite […] will return a `disk I/O error`

[https://fly.io/docs/litefs/primary/](https://fly.io/docs/litefs/primary/)

Perhaps you were unknowingly connecting to the other machine in the primary region, rather than to the actual primary machine? (They do hand off, in some circumstances.)

`fly logs` should help narrow this down, either way…

---

<div class="post-metadata">

**Author:** ![moorst](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/moorst/32/18688_2.png) [@moorst](https://community.fly.io/u/moorst)\
**Post date:** [March 20, 2024, 12:31pm UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/3 "2024-03-20T12:31:53Z")

</div>

Thank you for the prompt response and guidance 🙌 I must admit that I’m not very qualified in this space, I’m more of a frontend engineer.

It does look like it’s trying to update on a non-primary machine, I just don’t know why, or how I prevent this? Is additional configuration required?

For context, this is happening when a remix loader is attempting to update a user via prisma:

```auto
 prisma.user.update({
  where: { id },
  data: { ...user },
})

```

**PrismaClientUnknownRequestError:** Invalid `prisma.user.update()` invocation: Error occurred during query execution: ConnectorError(ConnectorError { user\_facing\_error: None, kind: QueryError(SqliteError { extended\_code: 778, message: Some(“disk I/O error”) }), transient: false })

How would I ensure that this write is always attempted on this primary?

I’m also pretty confused as to why I get the same error when connecting to the primary machine with prisma studio, when I am definitely choosing the primary machine?

---

<div class="post-metadata">

**Author:** ![moorst](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/moorst/32/18688_2.png) [@moorst](https://community.fly.io/u/moorst)\
**Post date:** [March 20, 2024, 1:27pm UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/4 "2024-03-20T13:27:28Z")

</div>

Following up - I have scaled back up to just two machines (`fly scale count 2 --region lhr`) in the primary region and still seeing the issue.

I set up log shipper to see if it surfaced anything else useful:

```auto
2024-03-20 13:14:35.577 [INFO] lhr ...3d708 GET /account 302 - - 90.359 ms
2024-03-20 13:14:35.577 [INFO] lhr ...3d708 GET /account 302 - - 90.359 ms
2024-03-20 13:14:36.302 [INFO] lhr ...3d708 level=INFO msg="fuse: write(): wal error: read only replica
2024-03-20 13:14:36.302 [INFO] lhr ...3d708 level=INFO msg="fuse: write(): wal error: read only replica

2024-03-20 13:14:36.312 [INFO] lhr ...3d708 ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteError { extended_code: 778, message: Some("disk I/O error") }), transient: false })
2024-03-20 13:14:36.312 [INFO] lhr ...3d708 ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteError { extended_code: 778, message: Some("disk I/O error") }), transient: false })
2024-03-20 13:14:37.133 [INFO] lhr ...3d708 GET /resources/stripe/create-customer 500 - - 1091.505 ms
2024-03-20 13:14:37.133 [INFO] lhr ...3d708 GET /resources/stripe/create-customer 500 - - 1091.505 ms
2024-03-20 13:14:37.181 [INFO] lhr ...336d8 HEAD / 200 - - 54.568 ms
2024-03-20 13:14:37.181 [INFO] lhr ...336d8 HEAD / 200 - - 54.568 ms

```

So the writes are happening on the replica (…3d708) and each request fires twice?

---

<div class="post-metadata">

**Author:** ![mayailurus](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/mayailurus/32/17593_2.png) [@mayailurus](https://community.fly.io/u/mayailurus)\
**Post date:** [March 21, 2024, 5:48am UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/5 "2024-03-21T05:48:43Z")

</div>

> [@moorst](#):
>
> How would I ensure that this write is always attempted on this primary?

The [LiteFS proxy](https://fly.io/docs/litefs/proxy/) was [added to make that much easier,](https://fly.io/blog/tracking-consistency-with-litefs/) although it does have several limitations.

One of them is that you can’t perform writes within a `GET` request. (From the logs, it looks like you might have such.)

> [@moorst](#):
>
> I’m also pretty confused as to why I get the same error when connecting to the primary machine with prisma studio, when I am definitely choosing the primary machine?

I’m surprised by this part, too.

How about trying with the `sqlite3` command line—from within `fly ssh console`—to reduce moving parts?

```plaintext
$ fly ssh console --machine ...336d8 # primary
# # note: this script is a little defensive about env vars not being defined, etc.
# test -d "${LITEFS_DIR:-not-there}" || echo litefs dir at unexpected location.
# test -f "${LITEFS_DIR}"/.primary && echo not primary. # should not exist
# sqlite3 "${DATABASE_PATH:-/not-there/missing.db}"
> create table TST (X int);
> insert into TST values (7);
> .q

```

Scanning the logs for recent `primary lease acquired` messages, to make sure they still match the machine ID, might also be prudent.

(The `test -f` way can give false positives.)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [March 28, 2024, 5:49am UTC](https://community.fly.io/t/sqlite-error-when-attempting-to-update-records-with-multiple-machines/18837/6 "2024-03-28T05:49:14Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
