Repository navigation
fix(messagequeue): drop partition signals instead of blocking when the channel is full - #1163
Conversation
sbalabanov
left a comment
There was a problem hiding this comment.
[mq-flake-2-reviewer] round 1/5: satisfied. No must-fix. Two nits inline.
Semantics. OnSignal is set only in test/integration/extension/messagequeue/mysql and in TestPartitionWorker_RunPollErrorLogging. Production wiring never sets it. Every integration channel has a buffer of 100, and every helper (waitForSignal, assertNoDelivery, waitForCondition, waitForLag, and the open-coded loop at queue_test.go:1679) drains first and then reads. The signals come from tickers, so a dropped signal is replaced on the next tick. The channel is only full while nobody is reading, and the next helper drains it anyway, so no helper can hang or miss a signal. The new semantics are also strictly better on one point. Before, a sender parked on a full channel delivered a stale, pre-drain signal right after drainSignals. Now that signal is dropped. I found no test that depends on backpressure, such as an undrained hook freezing a supervisor's heartbeat to force lease expiry. The unit test still synchronises: the first poll's signal always lands in the empty one-slot channel. Extra polls after cancel at most add more identical poll failed entries or one debug stop log, and the assertions tolerate both.
Workaround removal. Safe. The waitForCondition after the traffic loop drains before it reads, and nothing else in the suite relies on blocking delivery.
#1161. git merge-tree of this head with #1161's head (1fde991) is clean. There is no semantic conflict either: with the send non-blocking, the ctx.Done() branch that closes done (now explicit in #1161) is always reachable, whoever owns the hook.
PR body. "No tests added or changed" is slightly off, because queue_test.go loses two lines. Consider "No tests added; one obsolete drain removed."
Verified locally at 7765f32:
--@rules_go//go/config:race --test_filter='^TestPartitionWorker_RunPollErrorLogging$' --test_arg=-test.count=200 --runs_per_test=40passed (40/40).- The load-matched variant with
--runs_per_test=80 --local_test_jobs=80passed (80/80). - The full package under race with
--runs_per_test=10passed. //test/integration/extension/messagequeue/mysql:go_default_test(Docker) passed.
7765f32 to
ea472e9
Compare
sbalabanov
left a comment
There was a problem hiding this comment.
[mq-flake-2-reviewer] round 2/5: satisfied. No new findings.
git diff 7765f32c ea472e92 contains only the two doc edits for the round-1 nits:
- The
subscriber.OnSignalfield doc is now a one-line pointer toemitSignal. - The integration README line now sits below the signal table, so the colon-ended intro leads straight into the table again.
There are no code changes, and the emitSignal body and Params.OnSignal doc are unchanged. The drop-when-full contract is now stated in two places: emitSignal, which owns it, and Params.OnSignal, the public contract. The README carries it for test authors. My round-1 assessment of semantics, the workaround removal, and #1161 still holds.
Verified locally at ea472e9 with --@rules_go//go/config:race --nocache_test_results:
- Full
//platform/extension/messagequeue/mysql:go_default_test,--runs_per_test=10: passed (10/10). --test_filter='^TestPartitionWorker_RunPollErrorLogging$' --test_arg=-test.count=200 --runs_per_test=40: passed (40/40).
ea472e9 to
154b670
Compare
sbalabanov
left a comment
There was a problem hiding this comment.
[mq-flake-2-reviewer] owner-request pass (not counted): satisfied. No inline comments.
Delta. git diff ea472e92 154b6701 changes only the Params.OnSignal doc comment in sql.go. gofmt is clean.
Comment. Accurate, and four lines, within the five-line budget for exported docs.
- "one HookSignal per completed delivery check or ownership pass" matches the emitters:
SignalDeliveryCheckafter each poll tick inrun, andSignalPartitionUpdateafter each lease tick and discovery tick inmanagePartitions. - The drop rule is stated briefly with "(see emitSignal)", so its explanation still lives on
emitSignal. - The production warning is correct.
PR body, "Why dropping a signal is safe". I checked each claim against the code and the helpers, and all hold:
- A send can only be dropped when the buffer is full, so never while a receiver is parked.
- Every helper drains before it waits (
waitForLagthroughwaitForSignal). - The emitters are driven by tickers.
waitForConditionre-reads real state.- Every signal
assertNoDeliveryreceives is a real completed check, so N received means at least N cycles. - The unit test's first signal lands in the empty one-slot channel.
- Production never sets
OnSignal.
Optional wording notes, non-blocking. Nothing here needs to change before Ready:
- "or count them" is a little broader than intended.
assertNoDeliverycounts received signals legitimately, as a lower bound. "never infer how many occurred from how many arrived" would be exact. - The removed "pass a buffered channel" hint no longer appears anywhere. An unbuffered channel still works with the drain-then-block helpers, so this is only lost guidance.
- The body's Changes bullet still says the contract is documented on
subscriber.OnSignal. That field is now a pointer toemitSignal. The "needs only one signal" bullet also fitsassertNoDeliveryloosely, since it waits for N.
Verified locally at 154b670: //platform/extension/messagequeue/mysql:go_default_test --@rules_go//go/config:race --nocache_test_results passed. My earlier stress, race and integration results still apply, because the code has not changed since 7765f32.
…e channel is full Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
154b670 to
fb79153
Compare
Summary
The MySQL subscriber's
emitSignaldid a blocking send onOnSignal. A partition worker ormanagePartitionscould park on an undrained hook, including after its context was cancelled, which hangsTestPartitionWorker_RunPollErrorLoggingunder-raceand CPU load. Production is unaffected becauseOnSignalis nil there.Changes
emitSignalis now a non-blocking send (selectwithdefault); a signal is dropped while the channel is full, so a receiver learns "at least one such event", not "every".subscriber.OnSignalandParams.OnSignal.drainSignalscall in the GC-on-busy-partition integration test's traffic loop.queue_test.goworkaround is removed.Why dropping a signal is safe
waitForSignal,waitForCondition,assertNoDelivery,waitForLag) drains first and then needs only one signal emitted after it starts waiting.waitForConditionre-reads real state;assertNoDeliverycounts only real completed checks, so it observes at least N real cycles.OnSignal.Params.OnSignaldoc comment warns about this.Test Plan
Stress (80 parallel shards x 200 iterations,
-race):emitSignal).Also run:
./tool/bazel test //platform/extension/messagequeue/mysql:go_default_test --@rules_go//go/config:race --runs_per_test=10 --nocache_test_resultspasses../tool/bazel test //test/integration/extension/messagequeue/mysql:go_default_test --test_output=errors(Docker) passes.make build,lint,check-tidy,check-gazelle,check-mockspass.make testfails only on gpg commit-signing tests (environmental in this sandbox).🤖 Generated with Claude Code