Skip to content

Conversation

@fivestones
Copy link
Contributor

Problem

When starting the server against a fresh, empty database, the application enters a crash loop.

The instant.db.model.transaction/init function queries MAX(id) from the transactions table. On a fresh install, this table is empty, so Postgres returns NULL. The code attempts to cast this nil result to a primitive long via (long ...), resulting in a NullPointerException.

Because of this the server crashes and instantdb doesn't work at all.

Context

This appears to be a regression introduced in #2107. That PR added logic to populate the transaction ID on initialization but does not handle the case where the database is completely empty (returning nil).

Solution

Updated max-tx-id in src/instant/db/model/transaction.clj to handle the nil case by defaulting to 0.

Steps to Reproduce

(Assumes you are starting with a fresh install and there is not yet any database)

  1. git clone https://github.com/instantdb/instant.git
  2. Navigate to instant/server/.
  3. Run make docker-compose.
  4. Observe the crash in the logs during the init.finish.tx-model phase.

Copy link
Contributor

@stopachka stopachka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @fivestones !

@stopachka stopachka merged commit 3b71453 into instantdb:main Dec 28, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants