Skip to content

fix(cosift): wrap Pebble Close in sync.Once for idempotency (closes PILOT-190)#4

Merged
TeoSlayer merged 1 commit into
mainfrom
fix-pebble-double-close
May 28, 2026
Merged

fix(cosift): wrap Pebble Close in sync.Once for idempotency (closes PILOT-190)#4
TeoSlayer merged 1 commit into
mainfrom
fix-pebble-double-close

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

  • cockroachdb/pebble's *DB.Close() panics if called twice; PebbleStore.Close() passed the call through unprotected, so any layered cleanup (e.g. t.Cleanup + explicit defer, signal handler + main exit) could panic at shutdown
  • Add closeOnce sync.Once + closeErr error fields to PebbleStore and wrap the Pebble close in closeOnce.Do(...), caching and returning closeErr so every caller sees the same outcome
  • Same idiom previously applied to beacon Server.Close in PILOT-182

Files

  • internal/store/pebble.go — struct fields + Close() rewrite
  • internal/store/pebble_test.goTestPebbleStore_CloseIsIdempotent regression test (3 calls, assert no panic + stable return)

Test plan

  • go build ./... — clean
  • go test -race -count=3 -timeout 120s ./... — all packages pass 3x
  • go test -race -count=3 -run TestPebbleStore_CloseIsIdempotent ./internal/store/... — green

Closes PILOT-190.

cockroachdb/pebble's *DB.Close() panics if invoked twice. PebbleStore
passed the call through unprotected, so layered cleanups (e.g.
t.Cleanup + explicit defer, signal handler + main exit) could panic
the process at shutdown.

Wrap teardown in sync.Once and cache the first-call error in closeErr
so every caller sees the same outcome. Adds TestPebbleStore_CloseIsIdempotent
as a regression — opens a store, calls Close() three times, asserts
no panic and a stable return value.

Closes PILOT-190.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit 3e8f6db into main May 28, 2026
3 checks passed
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.

2 participants