Skip to content

M7 audit, part 1: the error model - #38

Merged
merlimat merged 3 commits into
mainfrom
m7-audit-errors
Nov 23, 2026
Merged

merlimat merged 3 commits into
mainfrom
m7-audit-errors

Conversation

@merlimat

@merlimat merlimat commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The first part of M7's audit: the error model (PLAN.md, M7; docs/7-api.md §6). Rustdoc and the examples follow
in their own pull requests.

Problem

Some failures reached the application under a kind that doesn't match the spec's categories (error-model §2–§3)
or Java V5's mapping (V5ExceptionMappings), and the docs didn't say what an operation fails with.

  • Broker codes without their category. ConsumerAssignError (Key_Shared ranges that overlap another
    consumer's) came out as Other; Java V5 makes it ConsumerBusy. InvalidTxnStatus and TransactionNotFound came
    out as Other; Java V5 makes them TransactionConflict. InvalidTopicName came out as Other, though only the
    application can change the name.
  • A refused handshake at a segment's broker was retried. When a producer or a consumer registers on a segment, a
    broker that refuses the connection, as for credentials it rejects, counted as no broker to ask: the client retried
    until the operation timeout and reported Timeout. A lookup reports the same refusal at once, as Authentication,
    which error-model §3 says the client doesn't retry.
  • An authentication provider's failure kept the provider's kind. A Token::from_fn callback that failed with
    Connect was retried for the whole operation timeout and ended as Timeout; one that failed with Other came out
    as Other. Java V5 reports a provider's failure as an authentication failure.
  • Long durations panicked. Duration::MAX, or any duration too long for a deadline, panicked with an overflow in
    receive_timeout, receive_batch, the send timeout, the batching delay, the ack group time and the keepalive
    interval, and hung create() for the operation and connect timeouts. docs/7-api.md §6 says nothing in the API
    panics on bad input. Short of the overflow, macOS's event loop refuses a wait of 68 years or more, and compio panics
    on that. Two other inputs panicked too: event_loops(usize::MAX), as the client reserved room for every loop up
    front, and initial_sequence_id(i64::MAX), whose next id overflowed in a debug build.
  • Undocumented. ErrorKind's variants had no docs, docs/7-api.md §6 didn't list Other, and no operation
    said which kinds it fails with.

Example

// A token provider that can't reach its service.
let token = Token::from_fn(|| async { Err(Error::new(ErrorKind::Connect, "the token service is down")) });
let client = local::PulsarClient::builder().service_url(url).authentication(token).build().await?;
let error = client.new_producer(Schema::string()).topic(topic).create().await.unwrap_err();
// Before: retried for the operation timeout, then `Timeout`. Now: `Authentication` at once, the provider's error as
// its source.

consumer.receive_timeout(Duration::MAX).await;
// Before: panicked, "overflow when adding duration to instant". Now: waits, as for a year.

The refused handshake, in RegisterError::from(Error): Error::server_error() only read a broker's refusal of a
request or a lookup, so ConnectionError::Refused { AuthenticationError } became RegisterError::Unavailable, which
the producer and the consumers retry.

Change

  • server_error_kind: ConsumerAssignError is ConsumerBusy, InvalidTxnStatus and TransactionNotFound are
    TransactionConflict, and InvalidTopicName is InvalidConfiguration.
  • Error::server_error() reads a refused handshake too, when its kind is one the client doesn't retry. A refusal
    it retries, such as ServiceNotReady, is still a failure to connect, as for a lookup. RegisterError::from turns
    any other authentication failure (a provider's, too many challenge rounds) into the broker's AuthenticationError,
    which isn't retried. A create, a subscribe and a producer's first send to a segment now fail with the refusal at
    once, as a lookup does. A producer already registered on the segment, registering again after a lost connection,
    retries refused credentials as it retries the connection, so that one failed token fetch doesn't fail the messages
    queued there; running consumers already subscribe a segment again after a backoff.
  • An authentication provider's failure is Authentication, with the provider's error as its source.
  • Durations are capped at a year: the client's connect, operation and keepalive settings, a producer's send timeout
    and batching delay, a consumer's ack group time and negative-ack delay, and the receive timeouts. Duration::MAX
    means "as long as it gets". deliver_after saturates at the latest time its field holds.
  • The thread-safe client grows its loops one by one, so a count too large to start fails with Other as the threads
    run out. The next sequence id is a u64, as on the wire, after the initial one or the broker's last.
  • A controller URL from the broker that doesn't parse is a malformed answer (Other), not the application's
    InvalidServiceUrl.
  • Docs: each ErrorKind says what it means and whether the client retries it; Error says how it prints and where
    its source is; every fallible operation of the producer, the three consumers, the clients and the decoders says
    which kinds it fails with. docs/7-api.md §6 lists Other, the mapping choices and the retry rule.

Testing

New tests: the broker codes' kinds; a refused handshake found in an error, and turned into a registration's refusal
or not; a Shared producer's send through a segment broker that refuses the credentials, which fails with
Authentication; a failing token provider, which fails a lookup with Authentication and keeps its error as the
source; and a client, a producer and a Queue consumer with Duration::MAX everywhere, which produce, receive and
acknowledge; a loop count of usize::MAX, which fails the build with Other; and a Shared producer whose initial
sequence id is i64::MAX, whose first message gets 2^63; and a registered segment's producer whose next
registration is refused the credentials, whose waiting message is stored once a retry succeeds. Each fails without its fix. cargo test --workspace, clippy for both feature sets, rustdoc with -D warnings and coverage
(measured as CI does) pass locally.

The first part of M7's audit (docs/7-api.md §6): the kinds that reach
the application follow the spec's categories (error-model §2-§3) and
Java V5's mapping, and the docs say what each operation fails with.

Kinds:
- A broker's ConsumerAssignError is ConsumerBusy, InvalidTxnStatus and
  TransactionNotFound are TransactionConflict, as Java V5 maps them;
  InvalidTopicName is InvalidConfiguration. They were Other.
- A broker that refuses the handshake when a producer or a consumer
  registers on a segment, as for credentials it rejects, fails the
  registration with its refusal, as a lookup does. It counted as no
  broker to ask: retried until the operation timeout, then Timeout.
- An authentication provider's failure is Authentication, with the
  provider's error as its source, as in Java V5. It kept the
  provider's own kind, retried or not by it.
- A controller URL from the broker that doesn't parse is a malformed
  answer, not the application's InvalidServiceUrl.

Durations: Duration::MAX, or any duration too long for a deadline,
panicked in receive_timeout, receive_batch, the send timeout, the
batching delay, the ack group time and the keepalive interval, and
hung create() for the operation and connect timeouts. Durations are
capped at a year, which macOS's event loop takes (it refuses a wait of
68 years or more). deliver_after saturates at the latest time its
field holds.

Docs: each ErrorKind says what it means and whether the client
retries it; every fallible operation of the producer, the consumers,
the clients and the decoders lists the kinds it fails with;
docs/7-api.md §6 lists Other, the mapping and the retry rule.
- event_loops(usize::MAX) panicked as the thread-safe client reserved
  room for every loop up front (capacity overflow). The loops are
  grown one by one: a count too large to start fails as the threads
  run out, with Other.
- initial_sequence_id(i64::MAX) overflowed computing the next id, a
  panic in a debug build. The next id is a u64, as on the wire, after
  the initial one or the broker's last.
With the first commit, credentials the broker refuses, or a provider
can't supply, fail a segment's registration at once. For a producer
already registered on the segment, registering again after a lost
connection, that failed every message queued there: one failed token
fetch lost them, where a retry may find fresh credentials. Such a
producer now retries them as it retries the connection, its messages
bounded by the send timeout; a first registration still fails with
them, as a lookup does. Running consumers already subscribe a segment
again after a backoff.
@merlimat
merlimat merged commit 311aaa7 into main Nov 23, 2026
14 checks passed
@merlimat
merlimat deleted the m7-audit-errors branch November 23, 2026 23:13
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.

1 participant