grist-core icon indicating copy to clipboard operation
grist-core copied to clipboard

@gristlabs/sqlite3 crashes with SIGILL when opening the database

Open darkuranium opened this issue 7 months ago • 1 comments

Describe the current behavior

Using Grist on a FreeBSD server crashes with a SIGILL.

I suspect the crash is related to the modifications in the @gristlabs/sqlite3 fork of node-sqlite3 (I've used the latter myself, and it worked fine last I tested --- though it's been a while).

This happens on multiple FreeBSD versions. The database file itself is fine, as Grist runs properly when the same exact file is hosted in Linux.

The crash happens in multiple version of FreeBSD 13, as well as 14.

Steps to reproduce

  1. Install Grist on FreeBSD, following the instructions on the website
  2. Start grist using yarn start:prod or a similar method
  3. Open a database on the web

Describe the expected behavior

The application should not crash.

Where have you encountered this bug?

Instance information (when self-hosting only)

  • Grist instance:

    • Version: v1.5.2, but it also crashes at least with v1.2.1
    • Installation mode: yarn install / yarn build:prod
  • Browser name, version and platforms on which you could reproduce the bug: any

  • Link to server log if relevant:

2025-01-05 15:47:59.358 - debug: Client sending clientConnect newClient=true, needReload=false, docsClosed=0, missedMessages=undefined, [email protected], org=tsi, altSessionId=kH3CE2wwFjUvQJVn9GJzGN, clientId=203afa9989669c6a, counter=51
2025-01-05 15:47:59.387 - info: Client onMessage '{"reqId":1,"method":"openDoc","args":["coGAha5vE6uakpxW9Ze83m",{"openMode":"defa... (118 length)' [email protected], org=tsi, altSessionId=kH3CE2wwFjUvQJVn9GJzGN, clientId=203afa9989669c6a, counter=51
2025-01-05 15:47:59.398 - debug: DocManager.openDoc Authorizer key { urlId: 'coGAha5vE6uakpxW9Ze83m', userId: 5, org: 'tsi' }
2025-01-05 15:47:59.417 - debug: DocManager.fetchDoc coGAha5vE6uakpxW9Ze83m
2025-01-05 15:47:59.435 - debug: ActiveDoc loadDoc access=owners, userId=5, [email protected], age=46, org=tsi, altSessionId=kH3CE2wwFjUvQJVn9GJzGN, clientId=203afa9989669c6a, counter=51, docId=coGAha5vE6uakpxW9Ze83m
2025-01-05 15:47:59.456 - debug: DB coGAha5vE6uakpxW9Ze83m open successfully
error Command failed with signal "SIGILL".

Node also generates a core dump; I won't be uploading the whole thing as it's nearly 250MB, but at least a backtrace might be of help:

Core was generated by `/usr/local/bin/node _build/stubs/app/server/server.js'.
Program terminated with signal SIGILL, Illegal instruction.
Privileged opcode.
#0  0x000000085bb07f81 in Marshaller::_writeBytes(void const*, unsigned long) ()
   from /usr/home/grist/grist-core/node_modules/@gristlabs/sqlite3/lib/binding/napi-v6-freebsd-unknown-x64/node_sqlite3.node
[Current thread is 1 (LWP 426848)]
(gdb) bt
#0  0x000000085bb07f81 in Marshaller::_writeBytes(void const*, unsigned long) ()
   from /usr/home/grist/grist-core/node_modules/@gristlabs/sqlite3/lib/binding/napi-v6-freebsd-unknown-x64/node_sqlite3.node
#1  0x000000085bb107b6 in node_sqlite3::Statement::Work_AllMarshal(napi_env__*, void*) ()
   from /usr/home/grist/grist-core/node_modules/@gristlabs/sqlite3/lib/binding/napi-v6-freebsd-unknown-x64/node_sqlite3.node
#2  0x00000000022ce924 in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::operator()(uv_work_s*) const ()
#3  0x00000000022ce7ff in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::__invoke(uv_work_s*) ()
#4  0x0000000826315519 in ?? () from /usr/local/lib/libuv.so.1
#5  0x000000082e7a4b05 in ?? () from /lib/libthr.so.3
#6  0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x860635000

darkuranium avatar Apr 30 '25 17:04 darkuranium

Hi @darkuranium, thanks for the report especially the backtrace! Your diagnosis looks correct, something funky in our patch to node-sqlite3 (in the "Marshaller"). cc @dsagal

If you were interested in debugging further, since you have the advantage of being on a FreeBSD setup, you could clone: https://github.com/gristlabs/node-sqlite3/ then do the following (might be slightly off, I find building this package a bit confusing and flail about every time):

npm install
npx node-pre-gyp configure
npm run build
npm run pretest
npm run test

Interested in whether you get a SIGILL during the tests.

paulfitz avatar Apr 30 '25 18:04 paulfitz