Skip to content

feat(pinner): add Close with ErrClosed lifecycle#1150

Draft
lidel wants to merge 1 commit intomainfrom
feat/pinner-close
Draft

feat(pinner): add Close with ErrClosed lifecycle#1150
lidel wants to merge 1 commit intomainfrom
feat/pinner-close

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Apr 24, 2026

This is an optional follow-up me and @gammazero discussed during colo this week. We could ass Close() to pinner to match other places in boxo (that have explicit Closer interface).

This PR

Pinner gains Close() error. Close waits for every in-flight operation, including streaming goroutines from RecursiveKeys, DirectKeys, and InternalPins, to finish. After Close, every other Pinner method fails fast with a new ErrClosed sentinel; streaming methods surface it as the Err of a single entry on the returned channel, which is then closed.

dspinner gains the matching implementation: Close is idempotent, admission is serialised with sync.Mutex + sync.WaitGroup, and stream sends select on a shutdown channel so a parked consumer cannot stall Close. The panic-recovery and context guards added in #1146 stay in place as defence in depth for hosts that do not wire Close correctly.

Hosts that own the backing datastore (e.g. kubo) should call Close on the pinner before closing the datastore to avoid use-after-close panics in pebble and similar stores.

Pinner gains Close() error. Close waits for every in-flight operation,
including streaming goroutines from RecursiveKeys, DirectKeys, and
InternalPins, to finish. After Close, every other Pinner method fails
fast with a new ErrClosed sentinel; streaming methods surface it as the
Err of a single entry on the returned channel, which is then closed.

dspinner gains the matching implementation: Close is idempotent,
admission is serialised with sync.Mutex + sync.WaitGroup, and stream
sends select on a shutdown channel so a parked consumer cannot stall
Close. The panic-recovery and context guards added in #1146 stay in
place as defence in depth for hosts that do not wire Close correctly.

Hosts that own the backing datastore (e.g. kubo) should call Close on
the pinner before closing the datastore to avoid use-after-close
panics in pebble and similar stores.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.16%. Comparing base (23c380b) to head (3cdde21).

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1150      +/-   ##
==========================================
+ Coverage   63.10%   63.16%   +0.06%     
==========================================
  Files         267      267              
  Lines       26777    26832      +55     
==========================================
+ Hits        16897    16948      +51     
- Misses       8158     8162       +4     
  Partials     1722     1722              
Files with missing lines Coverage Δ
pinning/pinner/dspinner/pin.go 66.40% <100.00%> (+2.85%) ⬆️
pinning/pinner/pin.go 31.25% <ø> (ø)

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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