You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
decdn fetch: concurrent invocations to the same new provider can double-open a channel #942
decdn fetch (#940) opens-or-reuses a buyer PaymentChannel per provider via get_by_provider → openChannel → store.record. That sequence is not atomic across the on-chain open, and the one-shot CLI has no cross-process in-flight guard (the node's BuyerChannelService has one — a per-provider opens_in_flight set). So two decdn fetch processes started simultaneously against the same provider for which no channel exists yet can both miss the reuse check and each submit openChannel. The second store.record (provider-keyed) overwrites the first, leaving one channel's deposit escrowed on-chain but untracked locally — reclaim-able only manually.
Preconditions (why it's rare)
Same provider, no prior live channel for it (first fetch), AND
Two fetch invocations overlapping within the open window.
Steady state (a channel already exists → both reuse) and distinct providers are unaffected.
Options
Cross-process file lock around the per-provider open (e.g. a lockfile in the data dir keyed by provider). Closes the local race but not the on-chain gap if the lock is bypassed.
Reconcile-after-open: re-read the store under a lock after openChannel; if a row for the provider already exists, prefer it and surface the just-opened channel for manual reclaim. Mirrors the node's TOCTOU re-check.
Document as a known limitation for v1 (the deposit is recoverable manually; the window is narrow).
A TOCTOU race in decdn fetch's channel open sequence: two simultaneous CLI processes targeting the same new provider can both pass the reuse-check gap and each submit openChannel on-chain. The second store.record overwrites the first, leaving one channel's deposit escrowed on-chain but untracked locally, recoverable only by manual reclaim. The window is narrow (first-ever fetch to a provider, concurrent invocations), and the common path is unaffected.
📊 Assessment
Dimension
Value
Reasoning
Type
Bug
Fund-loss (locked deposit) from a race condition, even if the window is rare
Labels
bug, technical, cli, low (unchanged)
Already correctly applied; low priority matches the narrow precondition
Coding agent
Suitable
Three concrete options are described; "reconcile-after-open" is a clear, self-contained implementation path mirroring the existing node-side TOCTOU re-check
The node's BuyerChannelService already handles this with a per-provider opens_in_flight set that acts as an in-process guard. The CLI needs an analogous mechanism that works cross-process. The reconcile approach is the safest because it tolerates the on-chain race without relying purely on local locking:
After openChannel returns, re-read store.get_by_providerunder a lock (file lock on a per-provider lockfile in $data_dir/locks/<provider_pubkey>.lock).
If a record now exists (written by a racing concurrent invocation that won), prefer the existing record and surface the just-opened channel for reclaim (log its channel ID with WARN-level guidance to manually reclaim the deposit).
If no record exists, write the new channel as normal.
Sub-tasks:
Add a per-provider file lock (e.g., fd-lock crate or flock(2)) in the CLI's open_or_reuse path
Implement the post-open TOCTOU re-check (store re-read under lock)
On double-open detection, log the orphaned channel ID with reclaim instructions
Add an integration test: two concurrent fetch processes → assert only one openChannel TX submitted (or both submitted but only one tracked, with the other logged)
Cross-process file lock option alone (without the reconcile re-check) doesn't close the on-chain gap if the lock is bypassed or if the process crashes between open and store.record, so prefer the combined approach.
Documentation fallback (option 3 from the issue) is reasonable for v1 given the narrow precondition, but the reconcile approach is low-effort enough to prefer over documenting a known fund-loss path.
Activity
github-actions commentedon Jun 17, 2026
🎯 Triage report
A TOCTOU race in
decdn fetch's channel open sequence: two simultaneous CLI processes targeting the same new provider can both pass the reuse-check gap and each submitopenChannelon-chain. The secondstore.recordoverwrites the first, leaving one channel's deposit escrowed on-chain but untracked locally, recoverable only by manual reclaim. The window is narrow (first-ever fetch to a provider, concurrent invocations), and the common path is unaffected.📊 Assessment
bug,technical,cli,low(unchanged)🔗 Similar issues
decdn fetchauto-open/track/reuse channels); this issue was self-reported during its PR review. Both issues also share the deferred expired-channel reclaim follow-up.💡 Notes and suggestions
Recommended fix: reconcile-after-open (mirrors node-side pattern)
The node's
BuyerChannelServicealready handles this with a per-provideropens_in_flightset that acts as an in-process guard. The CLI needs an analogous mechanism that works cross-process. The reconcile approach is the safest because it tolerates the on-chain race without relying purely on local locking:openChannelreturns, re-readstore.get_by_providerunder a lock (file lock on a per-provider lockfile in$data_dir/locks/<provider_pubkey>.lock).WARN-level guidance to manually reclaim the deposit).Sub-tasks:
fd-lockcrate orflock(2)) in the CLI'sopen_or_reusepathdecdn channel list --orphanedordecdn channel reclaimsub-command (ties into the deferred reclaim follow-up from Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940)fetchprocesses → assert only oneopenChannelTX submitted (or both submitted but only one tracked, with the other logged)Cross-process file lock option alone (without the reconcile re-check) doesn't close the on-chain gap if the lock is bypassed or if the process crashes between open and store.record, so prefer the combined approach.
Documentation fallback (option 3 from the issue) is reasonable for v1 given the narrow precondition, but the reconcile approach is low-effort enough to prefer over documenting a known fund-loss path.
Add this agentic workflows to your repo
To install this agentic workflow, run
fix(incentive): graceful failure on concurrent buyer-store open (#942) (
refactor(node,incentive): hoist the duplicated buyer-channel redb sto…