Skip to content

[Rust] Drain ack callbacks when closing a failed stream - #1193

Draft
dimitrije-djordjevic-db wants to merge 3 commits into
mainfrom
effort/core-close-callback-drain
Draft

dimitrije-djordjevic-db wants to merge 3 commits into
mainfrom
effort/core-close-callback-drain

Conversation

@dimitrije-djordjevic-db

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

ZerobusStream::close() on a stream that has already failed now waits for pending ack callbacks before it returns. Closes #1191.

When a stream fails, the SDK queues one on_error call per pending record. Before this change, close() on the failed stream returned Ok at once and never waited for them. Dropping or freeing the stream then aborted the callback task, and the queued on_error calls were lost. Now close() stops the supervisor and drains the callbacks, bounded by callback_max_wait_time_ms as on a normal close. It still returns Ok, as documented, but it can now take up to callback_max_wait_time_ms while callbacks finish. Multiplexed streams already drained every lane, so they are unchanged.

Why: a caller that uses on_error to learn which records failed could miss some of them. This affects every SDK with an ack callback.

How is this tested?

New tests in rust/tests/src/rust_tests.rs (callback_tests). They fail before the fix and pass after it:

  • close() on a failed stream waits while an on_error is blocked, then every queued on_error has arrived when it returns.
  • The callback time limit is respected; without a limit it waits for every callback; a cancelled close drains on retry; the callback limit is separate from the flush timeout; a non-retryable failure with recovery on drains too.

Guard tests, which pass before and after: dropping a failed stream does not wait for callbacks, and a failed multiplexed stream drains its callbacks on close.

make test (the full feature matrix) and make lint pass.

This pull request and its description were written by Isaac.

When a stream fails, close() must still wait for the queued on_error
callbacks before it returns. Add regression tests: close waits for
them and returns Ok; it respects a finite callback budget and an
explicit None; a cancelled close leaves the drain to the next close;
the budget is separate from flush_timeout_ms; the same holds after a
non-retryable failure with recovery on; drop doesn't wait; and a
failed 1-lane mux drains at close and returns the lane failure.

The close tests fail until close() drains the callbacks on a failed
stream.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
A failed stream is closed by its supervisor, which queues one
on_error callback per pending record. close() then saw the closed
flag and returned at once, so the callbacks it had not run yet were
dropped when the stream was freed.

On that path close() now stops the supervisor, so every on_error is
queued, then drains the callback task within
callback_max_wait_time_ms, as a normal close does. It still returns
Ok(()), and a second close after a completed one still does nothing.

Fixes #1191

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
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.

[Rust] close() on a failed stream drops queued ack-callback errors

1 participant