Skip to content

fix: remove outer transaction wrapper in sync to prevent PGlite deadlock#193

Open
Jpumpkin1223 wants to merge 1 commit intogarrytan:masterfrom
Jpumpkin1223:fix/pglite-nested-transaction-deadlock
Open

fix: remove outer transaction wrapper in sync to prevent PGlite deadlock#193
Jpumpkin1223 wants to merge 1 commit intogarrytan:masterfrom
Jpumpkin1223:fix/pglite-nested-transaction-deadlock

Conversation

@Jpumpkin1223
Copy link
Copy Markdown

Problem

When syncing more than 10 changed files, sync.ts wraps all importFile() calls inside a single engine.transaction():

const useTransaction = (filtered.added.length + filtered.modified.length) > 10;
if (useTransaction) {
  await engine.transaction(async () => { await processAddsModifies(); });
} else {
  await processAddsModifies();
}

However, importFile() opens its own inner transaction on the same DB connection. PGlite does not support nested transactions — the event loop hangs indefinitely with no error, no output, and no timeout.

This makes gbrain sync silently hang forever whenever a repo has more than 10 changed files.

Fix

Remove the conditional outer engine.transaction() wrapper. Each importFile() call is already individually atomic, so no outer wrapper is needed.

Reproduction

  1. Have a git repo with 11+ changed markdown files tracked in gbrain
  2. Run gbrain sync --repo <path>
  3. Observe: process hangs at 0% CPU indefinitely

Testing

Verified locally with a repo containing 17 changed files — sync now completes successfully.

When syncing >10 files, sync.ts wrapped all importFile() calls inside a
single engine.transaction(). However, importFile() opens its own inner
transaction on the same connection, and PGlite does not support nested
transactions — the event loop hangs indefinitely.

Remove the conditional outer transaction wrapper. Each importFile() call
is already individually atomic, so no outer wrapper is required.

Fixes: gbrain sync hanging forever when more than 10 files are changed.
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.

1 participant