Skip to content

fix: spawn lock + dead port reconnect#12

Merged
four-bytes-robby merged 1 commit into
mainfrom
fix/bus-spawn-reconnect
Jun 14, 2026
Merged

fix: spawn lock + dead port reconnect#12
four-bytes-robby merged 1 commit into
mainfrom
fix/bus-spawn-reconnect

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 14, 2026

Copy link
Copy Markdown
Member

Adds spawn lock to prevent duplicate bus binaries. scheduleReconnect now re-reads port file before retry.


Summary by cubic

Prevents duplicate bus processes during concurrent connects and fixes reconnects when the bus restarts on a new port.

  • Bug Fixes
    • Added a module-level spawn lock in BusClient so concurrent connect() calls share one in-flight spawn; extracted spawnBus() for clean lock release.
    • BusTui scheduleReconnect() now re-reads the port via discoverPort before retrying, avoiding dead cached ports after crashes/restarts.

Written for commit b96489a. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved concurrent connection request handling to prevent spawning multiple duplicate bus processes when multiple simultaneous connection attempts occur.
    • Enhanced reconnection logic to dynamically re-discover the bus port before attempting connections, instead of relying on previously cached port values. This ensures more reliable reconnection behavior when the bus port may have changed.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Walkthrough

Two bus connection fixes are applied: bus-client.ts gains a module-level spawnLock promise to deduplicate concurrent connect() auto-start calls so only one bus process is spawned, and bus-tui.ts updates scheduleReconnect to reset the cached port and re-run discoverPort before retrying open().

Changes

Bus connection robustness

Layer / File(s) Summary
spawnLock: serialize concurrent bus startup
src/bus-client.ts
Adds a module-scoped spawnLock: Promise<void> | null variable. startBus() returns the in-flight lock when one exists; otherwise it assigns spawnLock to the result of a new spawnBus() call and clears the lock in .finally() after the spawn attempt settles.
BusTui reconnect: reset port and re-discover
src/bus-tui.ts
In scheduleReconnect, resets this.port to 0 and awaits discoverPort(2000) before calling open(). If discovery throws, this.port stays 0 and open() is called anyway to handle the failure and keep the retry loop running.

Estimated code review effort

3 (Moderate) | ~20 minutes

Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: spawn lock + dead port reconnect' directly and specifically summarizes the two main changes: adding a spawn lock mechanism and fixing port re-discovery on reconnect.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Tip: You can configure your own custom pre-merge checks in the settings.

Finishing Touches
Generate docstrings
  • Create stacked PR
  • Commit on current branch
Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bus-spawn-reconnect
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/bus-spawn-reconnect

Comment @coderabbitai help to get the list of available commands and usage tips.

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