feat(storage): opt-in lossless watch delivery + stop watch workers on shutdown - #149
Merged
Conversation
…lback Add Options.LosslessWatch (and Server.LosslessWatch) to make storage->broadcast event sends block instead of dropping after SEND_TIMEOUT when a consumer stalls. Default unchanged (drop, for production write-hang resilience); enable where a dropped broadcast would desync a subscriber, notably deterministic tests. Make WatchWithCallback take a context so its per-shard goroutines exit on cancel, not only on storage Close — fixes a goroutine leak when a caller attaches a storage it does not own and detaches via context cancellation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CBosch101
approved these changes
Jun 16, 2026
CBosch101
left a comment
There was a problem hiding this comment.
Opt-in lossless watch delivery plus a context-cancellable WatchWithCallback to stop per-shard watchers when an owner detaches without closing the store. Clean, well-tested, default behavior preserved. The breaking signature change is already documented in the PR body and softened by accepting nil. APPROVE.
Verified
- Default path is unchanged:
blockingdefaults false andsendTimeoutdefaults toSEND_TIMEOUT(storage.go:105,159-163), so non-opt-in callers still hitSendWithTimeout(event, SEND_TIMEOUT)exactly as before. - Blocking send can't race
Close: the raw send runs underl.mutex.RLockinsendEvent(layered.go:828-832) whileClosetakes the write lock and nils the watcher (layered.go:173-179) — mutually exclusive, no send-on-closed-channel. SetBlockingruns underStart's write lock and is anatomic.Bool(layered.go:114, storage.go:88-89) — no race with concurrentsendEvent;-raceis green for the watch tests.- The blocking test is mutation-grounded (deleting the
s.blocking.Load()branch flips the negative assertion), and the drop-mode contrast test proves the buffer genuinely overflows. - nil ctx is treated as never-cancel rather than panicking on
ctx.Done()(layered.go:845-847).
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in lossless mode for real-time event delivery, and stops background watch workers from lingering after their owner shuts down. Closes #148.
What changed
Behavior & compatibility
nilis accepted and means never-cancel.Tests
-race.🤖 Generated with Claude Code