Skip to content

Use Harper readonly mode for Next.js builds#41

Open
cb1kenobi wants to merge 3 commits intomainfrom
use-readonly
Open

Use Harper readonly mode for Next.js builds#41
cb1kenobi wants to merge 3 commits intomainfrom
use-readonly

Conversation

@cb1kenobi
Copy link
Copy Markdown
Member

Next.js uses child processes to generate static pages. When those pages reference Harper data, it will try to load those databases and error with:

Error: IO error: While lock file: /Users/chris/harper/database/data/LOCK: Resource temporarily unavailable opening database /Users/chris/harper/database/data
    at openRocksDatabase (../harper/resources/databases.ts:162:22)
    at readRocksMetaDb (../harper/resources/databases.ts:407:16)
    at getDatabases (../harper/resources/databases.ts:247:6)
    at database (../harper/resources/databases.ts:734:2)
    at table (../harper/resources/databases.ts:899:20)
    at Object.<anonymous> (../harper/security/auth.ts:27:27)

Harper has a new READONLY environment variable that will allow a RocksDB database to be opened by another process in read-only mode allowing the static pages to be generated.

@cb1kenobi cb1kenobi requested a review from a team May 1, 2026 21:40
Copy link
Copy Markdown
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

I believe we need to (somehow) flush all the databases so the new process can "see" all the data.

@cb1kenobi
Copy link
Copy Markdown
Member Author

cb1kenobi commented May 2, 2026

I believe we need to (somehow) flush all the databases so the new process can "see" all the data.

plugin.ts imports 'harper' and runs on the thread that has write access to the database, so does Harper have any public API that will flush all databases?

@kriszyp
Copy link
Copy Markdown
Member

kriszyp commented May 2, 2026

plugin.ts imports 'harper' and runs on the thread that has write access to the database, so does Harper have any public API that will flush all databases?

No, I think we will need to add one.

Comment thread src/plugin.ts Outdated

// Next.js generates static pages using child processes and only a single process can open the
// RocksDB databases, so force Harper to start in read-only mode
process.env.READONLY = 'true';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm surprised this wasn't prefixed with like ROCKSDB_ or HARPER_, but thats an upstream thing so no concern here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea! Sit tight.

@Ethan-Arrowood
Copy link
Copy Markdown
Member

looks like this needs to wait until Harper is updated (or flushDatabases is added to the types export?)

@cb1kenobi
Copy link
Copy Markdown
Member Author

Yeah, this PR needs to wait a little bit.

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.

3 participants