Skip to content

semaphore: add leased Redis semaphore#79

Merged
raphael merged 6 commits into
mainfrom
fix/reader-close-self-deadlock
Jun 2, 2026
Merged

semaphore: add leased Redis semaphore#79
raphael merged 6 commits into
mainfrom
fix/reader-close-self-deadlock

Conversation

@raphael

@raphael raphael commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Add a new Redis-backed semaphore package for fleet-wide leased concurrency limits.
  • Document the new package in the root README and package README with a simple usage example.
  • Refresh Go dependencies with go get -u -v ./... and include semaphore/... in the CI race-test script.

Test plan

  • REDIS_PORT=6380 ./scripts/cibuild

Release note intent

This is intended to ship as v1.8.0: it adds a new public package without requiring changes for existing users.

raphael added 6 commits May 28, 2026 11:56
On a fatal read error (e.g. the underlying stream key being destroyed)
the reader read loop called Close synchronously. Close waits on the read
goroutine via wait.Wait, so calling it from that same goroutine deadlocked
and leaked the reader and its Redis connection; any external Close blocked
forever too.

Trigger the shutdown asynchronously so the read goroutine can return and
release the wait group. Close is already idempotent via sync.Once, so this
is safe alongside a concurrent external Close.

Adds a regression test that drives the real read loop through a simulated
fatal error (via a small xreadFn seam) and asserts the reader closes
instead of hanging. The test hangs on pre-fix code.
Move the test-only read hook from a Reader struct field to a package
variable so it no longer pollutes Reader. Behavior is unchanged; it
defaults to (*Reader).xread and is only overridden in tests.
Refresh Go dependencies for the release candidate and document the new leased semaphore package so users can discover and adopt it.
Include the new semaphore package in the race-test script so release checks cover its Redis-backed lease behavior.
@raphael raphael merged commit 9924fc6 into main Jun 2, 2026
5 checks passed
@raphael raphael deleted the fix/reader-close-self-deadlock branch June 2, 2026 17:03
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