Class FailedIpCooldownHolder
- java.lang.Object
-
- org.asynchttpclient.netty.channel.FailedIpCooldownHolder
-
public final class FailedIpCooldownHolder extends Object
Per-host failed-IP cooldown applied to a request's resolved addresses before a new connection is opened, independently of the configuredLoadBalancemode.When a connection attempt to an address fails,
markFailed(String, InetSocketAddress)puts that address in a short cooldown. While the cooldown is activereorder(String, List)moves the address to the back of the returned list rather than dropping it, so it is still available as a last-resort failover target and is re-probed once the window elapses. This bounds the cost of an IP that silently black-holes packets (drops them with no RST): without the cooldown every new connection targeting it would burn a fullconnectTimeoutbefore failing over; with it, only the occasional re-probe pays that cost. (An IP that actively refuses the connection fails over immediately and cheaply, with or without the cooldown.) Liveness remains governed at the DNS/resolver level — the cooldown is only a short-lived dampener, not a health checker.The cooldown only re-orders the resolved addresses; it never removes one, so failover always has somewhere to go. It tracks TCP connect failures only (TLS/handshake failures are not fed back here), matching where address-level failover happens.
Per-host state is held in a bounded map (capped at 4096); at the cap an arbitrary entry is evicted before a new one is added, so memory stays bounded even for clients that touch very many distinct hosts. Dropping a host's state is harmless — it simply forgets any cooldowns the next time the host is seen.
Thread-safe.
-
-
Constructor Summary
Constructors Constructor Description FailedIpCooldownHolder()FailedIpCooldownHolder(long cooldownNanos, LongSupplier nanoClock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidmarkFailed(String host, InetSocketAddress address)Records that a connection attempt toaddress(forhost) failed, so subsequentreorder(java.lang.String, java.util.List<java.net.InetSocketAddress>)calls move it to the back forDEFAULT_FAILED_IP_COOLDOWN.List<InetSocketAddress>reorder(String host, List<InetSocketAddress> addresses)Re-ordersaddressesso that any address currently in cooldown is moved to the back (otherwise preserving the incoming order).
-
-
-
Constructor Detail
-
FailedIpCooldownHolder
public FailedIpCooldownHolder()
-
FailedIpCooldownHolder
public FailedIpCooldownHolder(long cooldownNanos, LongSupplier nanoClock)
-
-
Method Detail
-
reorder
public List<InetSocketAddress> reorder(String host, List<InetSocketAddress> addresses)
Re-ordersaddressesso that any address currently in cooldown is moved to the back (otherwise preserving the incoming order).- Parameters:
host- the connection's target host (the key the matchingmarkFailed(java.lang.String, java.net.InetSocketAddress)calls use)addresses- the resolved socket addresses, in their incoming order- Returns:
- the same list instance when there is nothing to do (size
<= 1, or no address is in cooldown), otherwise a new list with the cooling addresses moved to the back
-
markFailed
public void markFailed(String host, InetSocketAddress address)
Records that a connection attempt toaddress(forhost) failed, so subsequentreorder(java.lang.String, java.util.List<java.net.InetSocketAddress>)calls move it to the back forDEFAULT_FAILED_IP_COOLDOWN. No-op when the host is not (or no longer) tracked — we never resurrect an evicted entry, which keeps the failure path from growing the map for hosts that are not actively being connected to.
-
-