Skip to content

Wait for open before suspending and release waiters if suspend fails - #126

Merged
kasperisager merged 1 commit into
holepunchto:mainfrom
bluenix:fix-suspend-while-opening
Oct 30, 2026
Merged

kasperisager merged 1 commit into
holepunchto:mainfrom
bluenix:fix-suspend-while-opening

Conversation

@bluenix

@bluenix bluenix commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Calling suspend() while the database is still opening deadlocks it. _suspend() sets this.resumed = rrp() and then calls binding.suspend(), which throws invalid argument (EINVAL) because the open hasn't finished. The throw skips this._suspended = true, so this.resumed is never resolved: resume() sees _suspending === _suspended, returns without calling _resume(), and every later get(), write, flush or compact waits forever in waitForResume(). Smallest repro:

const db = new RocksDB(dir)
db.ready()
await db.suspend().catch(() => {}) // Error: invalid argument
await db.resume()
await db.get('hello') // never resolves

The fix makes _suspend() wait for the open first, like every other operation in RocksDBState, and if the native suspend still fails it clears and resolves this.resumed before rethrowing, so a failed suspend no longer leaves the database hung.

The new test fails without the fix (Error: invalid argument from binding.suspend) and passes with it. The full suite passes on Node and Bare (85/85).

Analysed with help from Claude (AI).

🤖 Generated with Claude Code

_suspend() sets this.resumed before calling binding.suspend(), but never waits for the database to open. Calling suspend() while the open is still in flight makes binding.suspend() throw "invalid argument" (EINVAL), and because the throw skips both `this._suspended = true` and any cleanup, this.resumed stays pending forever: resume() then sees _suspending === _suspended and returns without calling _resume(), so every later read, write, flush or compact hangs in waitForResume(). This waits for the open first, like every other operation in RocksDBState, and if the native suspend still fails it clears and resolves this.resumed before rethrowing, so a failed suspend leaves the database usable instead of hanging.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@bluenix
bluenix requested a review from a team October 30, 2026 11:49

@kasperisager kasperisager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, great catch! The change looks good, I'll land and release when green.

@kasperisager
kasperisager merged commit c161111 into holepunchto:main Oct 30, 2026
8 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