#[non_exhaustive]pub struct PgListenerOptions {
pub reconnect: bool,
pub backoff_initial: Duration,
pub backoff_max: Duration,
pub keepalive_idle: Duration,
pub ping_interval: Duration,
pub buffer: usize,
pub max_reconnect_attempts: Option<u32>,
}Expand description
Tuning for a PgListener; see PgListener::builder.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.reconnect: boolReconnect after the connection is lost, re-issuing LISTEN for every
tracked channel: the loss is reported as
PgListenerEvent::Disconnected and the re-established connection
as PgListenerEvent::Reconnected. When false, connection loss is
terminal and PgListener::recv returns the error (no
Disconnected). Default: true.
backoff_initial: DurationDelay before the first reconnect attempt; it doubles after every
attempt, up to backoff_max, and only starts
over once a re-established connection has stayed up for a
ping_interval (so a server that keeps
dropping new connections is not hammered). Each delay is scaled by a
random factor between 0.5 and 1 (jitter). Must be non-zero and at
most backoff_max. Default: 100 ms.
backoff_max: DurationUpper bound on the reconnect delay. Default: 30 s.
keepalive_idle: DurationTCP keepalive idle time on the listener connection. Counted in whole seconds; must be at least 1 s. Default: 60 s.
ping_interval: DurationLiveness check period. When no notification arrived during an
interval, SELECT 1 is sent; if it fails or is not answered within
another interval, the connection is treated as lost. This detects
half-open connections long before TCP keepalive does. The same bound
applies to LISTEN / UNLISTEN commands: one not answered in time
fails with a timeout error and the connection is treated as lost.
Each connection attempt (TCP connect, TLS and the startup handshake)
is bounded by PgConfig::connect_timeout plus this (the driver
applies connect_timeout to each address the host resolves to, so
an address that times out leaves this long for the next one and the
handshake). Must be at least 100 ms and at most one day.
Default: 30 s.
buffer: usizeCapacity of the notification queue. When it is full, further
notifications are dropped and reported as
PgListenerEvent::Lagged. Must be at least 1 and at most tokio’s
Semaphore::MAX_PERMITS, the
largest bounded channel tokio supports. Default: 1024.
max_reconnect_attempts: Option<u32>Give up after this many failed reconnect attempts in a row (counted
per outage): the listener then stops, and PgListener::recv
returns the last attempt’s error once the queue is drained. None
retries for as long as the listener exists. Must be at least 1;
to never reconnect, disable reconnect.
Whatever this is set to, the listener also gives up after three
attempts in a row that the server refuses with SQLSTATE class 28
(invalid authorization: a wrong password, a pg_hba.conf rejection)
or 3D000 (the database does not exist). Retrying cannot fix those,
and retrying bad credentials forever can lock the role or trip
intrusion detection. Default: None.