Skip to content

Release on_failure: :noop messages from streaming lease management - #116

Open
reidmorrison wants to merge 4 commits into
elixir-broadway:mainfrom
reidmorrison:docs/streaming-noop-lease-extension
Open

reidmorrison wants to merge 4 commits into
elixir-broadway:mainfrom
reidmorrison:docs/streaming-noop-lease-extension

Conversation

@reidmorrison

@reidmorrison reidmorrison commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

With the pull producer, on_failure: :noop leaves 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's outstanding map 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 :noop so that it releases the message from lease management and lets the current deadline lapse.

Changes

  • StreamManager.release/2: removes the ack_ids from outstanding (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 :noop action now calls it, for both on_success and on_failure.
  • Docs: the :noop acknowledgement, the :on_failure option, Lease management and the 2.0 upgrade guide now say that a :noop message is redelivered when the deadline from its last lease extension expires. The producer sets that deadline (10 to 600 seconds), not the subscription's ackDeadlineSeconds, so the docs recommend {:nack, seconds} for a predictable redelivery delay. The upgrade guide's streaming example now uses {:nack, 60}.
  • Graceful shutdown docs and the :drain_timeout_ms option: these described the drain timer as blocking shutdown. Broadway only waits for the processors and batchers; the producer's terminate/2 then nacks whatever is still outstanding. Both are rewritten (on top of 2.1.0's half-close step).
  • Two drain fixes found while testing this:
    • After a drain timed out, a late ack, nack or lease tick called maybe_complete_drain with drain_started_at: nil and crashed the StreamManager with an ArithmeticError. A :drain_timeout already in the mailbox after the drain completed is now ignored too.
    • A drain now completes when lease extension drops the last outstanding message (past :max_extension_ms), instead of waiting for :drain_timeout_ms and reporting a timeout.
  • CHANGELOG entries under Unreleased.

Tests cover the acknowledger releasing :noop messages, release/2 (no further lease extension, processing time recorded, unknown ack_ids ignored, drain completion), and both drain fixes.

Code Review.

Fixed:

  • The CHANGELOG said a released message is redelivered "like with the pull producer"; it now says the deadline comes from the last lease extension, not ackDeadlineSeconds.
  • The new drain and release tests matched telemetry events from any StreamManager, so a concurrent async test could satisfy them. Each test now tags its manager through :telemetry_metadata and matches on the tag.
  • The drain test now detaches its telemetry handler in on_exit.

Declined:

  • Emitting a telemetry event for released messages: nacks do not emit one either, and a new public event seemed out of scope here. Happy to add one if you would like it.

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.
@rockneurotiko

Copy link
Copy Markdown
Contributor

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 :noop should be discouraged on streaming, I think it's not gonna respect the default subscription deadline since the library do the automatic extended lease.

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).
@reidmorrison reidmorrison changed the title Document that on_failure: :noop keeps the streaming lease extended Release on_failure: :noop messages from streaming lease management Nov 20, 2026
@reidmorrison

Copy link
Copy Markdown
Contributor Author

Thanks, releasing the message is the better fix. I've reworked the PR that way:

  • :noop (for both on_success and on_failure) now calls a new StreamManager.release/2. It removes the message from outstanding without sending anything to Pub/Sub, so the lease stops being extended and the current deadline lapses. It also records the processing time like ack and nack do, and lets a drain finish if that was the last outstanding message.
  • I agree about discouraging :noop on streaming. The docs now say the redelivery delay comes from the producer's adaptive lease deadline (10 to 600 seconds), not the subscription's ackDeadlineSeconds, and recommend {:nack, seconds} when you want a predictable delay. The upgrade guide's streaming example uses {:nack, 60} now.

While testing it I found two small drain issues and fixed them here too:

  1. After a drain timed out, a late ack, nack or lease tick crashed the StreamManager with an ArithmeticError, because drain_started_at was already nil.
  2. A drain now completes when lease extension drops the last outstanding message, instead of waiting for :drain_timeout_ms and reporting a timeout.

If you'd rather have those as a separate PR, I'm happy to split them out.

I also merged the latest main (2.1.0) and kept its half-close step in the Graceful shutdown docs. CI is green.

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.

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