interledger-deprecated / five-bells-ledger

Open-source reference ledger optimized for use with the Interledger protocol
Other
27 stars 21 forks source link

sqlite in-memory database disappears and ledger crashes #354

Open dappelt opened 7 years ago

dappelt commented 7 years ago

Description

When starting the ledger with an in-memory sqlite database, the database disappears after a few minutes. When the ledger tries to query a (non-existing) table, it crashes.

Steps to reproduce

Open terminal, switch into the root folder of the ledger repo and run

LEDGER_PORT=3001 \
LEDGER_PUBLIC_URI=http://localhost:3001 \
LEDGER_ILP_PREFIX=demo.ledger2. \
LEDGER_DB_URI=sqlite://:memory: \
LEDGER_ADMIN_PASS="mypassword" \
DEBUG=* \
npm start

Wait a few minutes. Then, execute curl http://localhost:3001 and the ledger will fail with:

2016-11-09T11:45:06.321Z error-handler error { Error: SQLITE_ERROR: no such table: L_ACCOUNTS errno: 1, code: 'SQLITE_ERROR' }
2016-11-09T11:45:06.321Z error-handler error Error: SQLITE_ERROR: no such table: L_ACCOUNTS

The problem might be that the connection to the in-memory database is released and, thus, sqlite removes the database. See here.

justmoon commented 7 years ago

This sounds this issue: https://github.com/tgriesser/knex/issues/1701

Note that to reproduce with current ledger you have to access /accounts because the root endpoint no longer accesses the database.

stevenroose commented 7 years ago

I tried the same (LEDGER_ADMIN_PASS=mypassword LEDGER_DB_URI=sqlite://:memory: npm start), and I get the same error when doing PUT /accounts/alice:

Unhandled rejection Error: SQLITE_ERROR: no such table: L_ACCOUNTS

dappelt commented 7 years ago

Thanks for reporting. Currently, sqlite in-memory databases do not work very reliably with five-bells-ledger. As a workaround, try to store the sqlite database in a file, e.g. LEDGER_ADMIN_PASS=mypassword LEDGER_DB_URI=sqlite:///some/path/ledger.sqlite npm start or use postgres.