From a123101ef7f56cd57df58e2063a9064457b2273f Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Wed, 5 Nov 2025 17:11:22 +0100 Subject: [PATCH] ADR-40: Custom server pool and reconnecting to specific server Signed-off-by: Piotr Piotrowski --- adr/ADR-40.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/adr/ADR-40.md b/adr/ADR-40.md index 878c9387..7734c492 100644 --- a/adr/ADR-40.md +++ b/adr/ADR-40.md @@ -7,11 +7,12 @@ | Status | Implemented | | Tags | client, server, spec | -| Revision | Date | Author | Info | -| -------- | ---------- | -------- | ---------------------------- | -| 1 | 2023-10-12 | @Jarema | Initial draft | -| 2 | 2024-6-24 | @aricart | Added protocol error section | -| 3 | 2024-9-30 | @Jarema | Add connection Statistics | +| Revision | Date | Author | Info | +| -------- | ---------- | --------- | -------------------------------------------- | +| 1 | 2023-10-12 | @Jarema | Initial draft | +| 2 | 2024-6-24 | @aricart | Added protocol error section | +| 3 | 2024-9-30 | @Jarema | Add connection Statistics | +| 4 | 2025-11-05 | @piotrpio | Add custom server pool and reconnect handler | ## Summary @@ -125,6 +126,46 @@ all reconnect options are respected. For most clients, that means having a `reconnect` method on the Client/Connection handle. +#### Custom server pool + +Client should have a way to specify custom server pool for reconnection +attempts. When specified, client should use only those servers for reconnection +attempts, ignoring any advertised servers from the Server. + +New pool should be used for all reconnection attempts until the client is +restarted or a new pool is specified. New pool is subject to the same rules as +the default one - randomization unless disabled, max reconnect attempts, etc. + +```go +// SetServerPool sets a new server pool for reconnection attempts. +// It replaces any existing pool, including advertised servers. +func (nc *Conn) SetServerPool(servers []string) error +``` + +#### Reconnect to specific server + +Client should expose an option to configure a callback that will be called +before each reconnection attempt. + +As arguments, it should receive the list of servers that are in the pool +(together with reconnect attempt number), as well as the most up-to-date server +INFO. + +The callback should return the server URL to which the client should attempt to +reconnect (a url outside of the pool should not be allowed). Additionally, the +callback should allow to specify whether client should include a delay before +attempting to reconnect to the selected server (based on what's configured in +the client options). + +```go +// Return values: +// - url.URL: The server URL to connect to. Can be from the provided servers slice +// or a new server URL. New servers will be automatically added to the pool. +// - bool: If true, apply reconnect delay (ReconnectWait + jitter or CustomReconnectDelayCB) +// before attempting connection. If false, attempt connection immediately. +type ReconnectToServerHandler func([]Server, ServerInfo) (*url.URL, bool) +``` + #### Detecting disconnection There are two methods that clients should use to detect disconnections: