Skip to content

fix: attach a core first opened by a passive session when an active store gets it - #186

Open
danielAsaboro wants to merge 1 commit into
holepunchto:mainfrom
danielAsaboro:fix/active-session-after-passive
Open

danielAsaboro wants to merge 1 commit into
holepunchto:mainfrom
danielAsaboro:fix/active-session-after-passive

Conversation

@danielAsaboro

Copy link
Copy Markdown

_openCore sets core.replicator.ondownloading to check this.active, where this is the store that created the core. The hook only fires when the core starts downloading. If a passive session (store.session({ active: false })) opens the core first, the hook fires once, sees active: false and does nothing. A later session from an active store reuses the core, which is already downloading, so the hook never fires again. The core is never attached to the existing replication streams, and get() on the active session hangs.

Now every store that opens the core can mark it active (core.storeActive), and the hook checks that flag. When an active store reuses a core that is already open and downloading, it attaches it to the streams right away.

validation

The new test in test/basic.js replicates from a passive store, opens the core through a passive session and then through the active store. Without the fix, b.get(0) times out with REQUEST_TIMEOUT; with it, it returns the block. Node and Bare 55/55, npm run lint clean.

@danielAsaboro
danielAsaboro requested a review from a team November 3, 2026 20:00
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Fixes shared cores that remain unattached when a passive store opens them before an active store.

  • Active stores can attach cores first opened by passive sessions.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Passive store opens core] --> B[storeActive is false]
  B --> C[Active store reuses core]
  C --> D[Set storeActive to true]
  D --> E{Core open and downloading?}
  E -->|Yes| F[Attach to existing streams]
  E -->|No| G[Attach when downloading starts]
Loading

Reviews (1) · Last reviewed commit: "attach cores opened by a passive session..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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