Repository navigation
Release on_failure: :noop messages from streaming lease management - #116
reidmorrison wants to merge 4 commits into
Conversation
With the pull producer, :noop lets the message's ack deadline lapse. With the streaming producer the acknowledger sends nothing, so the message stays in outstanding and its lease keeps being extended until max_extension_ms. Say so in the moduledoc, the on_failure option and the 2.0 upgrade guide, which suggested :noop to keep the 1.x behaviour.
|
Hey! That's a good catch! I think the best idea here would be to remove from the lease management and let it expire at the current deadline. Maybe even |
The streaming acknowledger did nothing for :noop, so the message stayed in
the StreamManager's outstanding map and its lease kept being extended until
max_extension_ms (default 60 minutes). A graceful shutdown also waited for
it until drain_timeout_ms and then nacked it per on_shutdown.
Add StreamManager.release/2, which removes the ack_ids from outstanding
(recording their processing time, as ack and nack do) without sending
anything to Pub/Sub, and call it for :noop. The message is then redelivered
when its current ack deadline expires, as with the pull producer. Because
that deadline is set by the lease manager rather than the subscription's
ackDeadlineSeconds, the docs recommend {:nack, seconds} for a predictable
redelivery delay.
Answers /code-review high of docs/streaming-noop-lease-extension at 21dda8c. - The Graceful shutdown section and the :drain_timeout_ms option doc described the drain timer as blocking shutdown. Broadway's Terminator only waits for the processors and batchers; the producer's terminate/2 then nacks what is still outstanding per :on_shutdown. Rewrite both, and say that messages released by a :noop acknowledgement are not nacked. - The CHANGELOG entry repeated that a shutdown waited :drain_timeout_ms for a :noop message. Say that it was nacked per :on_shutdown instead. - The upgrade guide told streaming users to set on_failure: :noop and then said that does not give 1.x behaviour. Show {:nack, 60} for the streaming producer. - Complete a drain when lease extension drops the last outstanding message (a message past max_extension_ms), instead of waiting for the drain timer and reporting a timeout. - Fix a StreamManager crash: after a drain timed out, a late ack, nack or lease tick called maybe_complete_drain with drain_started_at nil and raised ArithmeticError. Also ignore a :drain_timeout already in the mailbox when the drain completed. Answers /code-review high of docs/streaming-noop-lease-extension at dd80cda. - The CHANGELOG said a released :noop message is redelivered "like with the pull producer". Say instead that the deadline comes from its last lease extension (10 to 600 seconds), not the subscription's ackDeadlineSeconds. - The new drain and release tests matched telemetry events from any manager, so a concurrent async test could satisfy them. Tag each test's manager through :telemetry_metadata and match on the tag. - Detach the drain test's telemetry handler in on_exit, so a failed assertion does not leave it attached. - Replace an em dash in a test section comment.
Resolve conflicts in CHANGELOG.md (keep this PR's entries under Unreleased, above 2.1.0) and in the Graceful shutdown section of producer.ex (keep 2.1.0's half-close step, plus this PR's corrected steps 3 and 4 and the :drain_timeout_ms paragraph).
|
Thanks, releasing the message is the better fix. I've reworked the PR that way:
While testing it I found two small drain issues and fixed them here too:
If you'd rather have those as a separate PR, I'm happy to split them out. I also merged the latest One open question: should a release emit a telemetry event? I left it out because nacks don't emit one either, but I can add it if you think it would help. |
With the pull producer,
on_failure: :noopleaves the message unacked and Pub/Sub redelivers it after the ack deadline. With the streaming producer, the acknowledger did nothing for:noop, so the message stayed in the StreamManager'soutstandingmap and the lease manager kept extending its lease until:max_extension_ms(default 60 minutes). On shutdown it was then nacked per:on_shutdown.As discussed in the comments, this PR changes
:noopso that it releases the message from lease management and lets the current deadline lapse.Changes
StreamManager.release/2: removes the ack_ids fromoutstanding(recording their processing time, as ack and nack do) without sending anything to Pub/Sub, and completes a drain if that was the last outstanding message. The acknowledger's:noopaction now calls it, for bothon_successandon_failure.:noopacknowledgement, the:on_failureoption, Lease management and the 2.0 upgrade guide now say that a:noopmessage is redelivered when the deadline from its last lease extension expires. The producer sets that deadline (10 to 600 seconds), not the subscription'sackDeadlineSeconds, so the docs recommend{:nack, seconds}for a predictable redelivery delay. The upgrade guide's streaming example now uses{:nack, 60}.:drain_timeout_msoption: these described the drain timer as blocking shutdown. Broadway only waits for the processors and batchers; the producer'sterminate/2then nacks whatever is still outstanding. Both are rewritten (on top of 2.1.0's half-close step).maybe_complete_drainwithdrain_started_at: niland crashed the StreamManager with anArithmeticError. A:drain_timeoutalready in the mailbox after the drain completed is now ignored too.:max_extension_ms), instead of waiting for:drain_timeout_msand reporting a timeout.Tests cover the acknowledger releasing
:noopmessages,release/2(no further lease extension, processing time recorded, unknown ack_ids ignored, drain completion), and both drain fixes.Code Review.
Fixed:
ackDeadlineSeconds.:telemetry_metadataand matches on the tag.on_exit.Declined: