Skip to content

Add endpoint connection-lifecycle hooks and a configurable establishment timeout#86

Merged
thisisnsh merged 1 commit into
bloomberg:mainfrom
flamble:endpoint-lifecycle-hooks
Jul 15, 2026
Merged

Add endpoint connection-lifecycle hooks and a configurable establishment timeout#86
thisisnsh merged 1 commit into
bloomberg:mainfrom
flamble:endpoint-lifecycle-hooks

Conversation

@flamble

@flamble flamble commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Give callers more insight into and control over connection establishment:

  • rmqt::Endpoint gains onConnectSuccess()/onConnectFailed() lifecycle hooks (no-op by default) so an endpoint can observe when a connection is established, or is down and will be retried -- useful for monitoring or metrics. The hooks are invoked synchronously on the connection's event-loop thread, after the critical connection bookkeeping, and each call is wrapped so a throwing override cannot propagate into the event loop. onConnectFailed() fires only on retriable failures, not on terminal ones.

  • RabbitContextOptions::setConnectionEstablishmentTimeout() makes the bound on a single connection-establishment attempt configurable (the default is unchanged), so callers can tune how long a stalled attempt may run before it is retried. The timer is applied at millisecond granularity, so a sub-millisecond value is rejected (asserted, and logged) to avoid an immediate-expiry retry loop that could never establish.

    This is a separate option from setConnectionErrorThreshold(): the error threshold governs how long a repeatedly failing connection keeps retrying before the error is surfaced to the application, whereas the establishment timeout bounds a single connect-and-handshake attempt before it is aborted and retried. A caller may want a short per-attempt bound (fail fast, retry sooner) while still tolerating a long overall retry window, so the two are tuned independently.

Also downgrade the hung-connection-establishment timeout log from BALL_LOG_FATAL to BALL_LOG_ERROR. Now that the establishment timeout is configurable (and can be short), an expiry is an expected, self-healing event -- the attempt is torn down and retried -- so FATAL over-states it. ERROR keeps it loud enough to show a disconnect period without implying the process is unusable. Any monitoring keyed on the previous FATAL severity of this message should move to ERROR; the hung_connection_reset metric is unchanged and is the severity-independent signal.

Includes unit tests for the hooks and the configurable timeout.

…ent timeout

Give callers more insight into and control over connection establishment:

- `rmqt::Endpoint` gains `onConnectSuccess()`/`onConnectFailed()` lifecycle
  hooks (no-op by default) so an endpoint can observe when a connection is
  established, or is down and will be retried -- useful for monitoring or
  metrics. The hooks are invoked synchronously on the connection's event-loop
  thread, after the critical connection bookkeeping, and each call is wrapped so
  a throwing override cannot propagate into the event loop. `onConnectFailed()`
  fires only on retriable failures, not on terminal ones.
- `RabbitContextOptions::setConnectionEstablishmentTimeout()` makes the bound on
  a single connection-establishment attempt configurable (the default is
  unchanged), so callers can tune how long a stalled attempt may run before it
  is retried. The timer is applied at millisecond granularity, so a
  sub-millisecond value is rejected (asserted, and logged) to avoid an
  immediate-expiry retry loop that could never establish.

  This is a separate option from `setConnectionErrorThreshold()`: the error
  threshold governs how long a *repeatedly failing* connection keeps retrying
  before the error is surfaced to the application, whereas the establishment
  timeout bounds a *single* connect-and-handshake attempt before it is aborted
  and retried. A caller may want a short per-attempt bound (fail fast, retry
  sooner) while still tolerating a long overall retry window, so the two are
  tuned independently.

Also downgrade the hung-connection-establishment timeout log from
`BALL_LOG_FATAL` to `BALL_LOG_ERROR`. Now that the establishment timeout is
configurable (and can be short), an expiry is an expected, self-healing event --
the attempt is torn down and retried -- so `FATAL` over-states it. `ERROR` keeps
it loud enough to show a disconnect period without implying the process is
unusable. Any monitoring keyed on the previous `FATAL` severity of this message
should move to `ERROR`; the `hung_connection_reset` metric is unchanged and is
the severity-independent signal.

Includes unit tests for the hooks and the configurable timeout.
@flamble flamble requested a review from thisisnsh July 15, 2026 15:06
@flamble flamble marked this pull request as ready for review July 15, 2026 15:45
@thisisnsh thisisnsh merged commit 059afaf into bloomberg:main Jul 15, 2026
4 checks passed
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