core (xmpp): Cache unreachable server on presence error to avoid disco queries:

In case of dead server/component with lot of contacts, we may receive a lot of
`<presence>` error with `remote-server-not-found` conditions. This patch use this to mark
the server as unreachable and avoid to do disco queries there.
This commit is contained in:
Goffi 2026-05-03 10:48:17 +02:00
commit 6e723b58a6

View file

@ -2268,6 +2268,25 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile
)
def errorReceived(self, presence):
"""Handle error presence.
Cache unreachable servers to avoid future disco queries.
"""
try:
e = error.exceptionFromStanza(presence)
assert isinstance(e, error.StanzaError)
if e.condition == "remote-server-not-found":
from_jid = jid.JID(presence["from"])
server_jid = jid.JID(from_jid.host)
self.host.memory.disco._jid_disco_cache[server_jid] = (None, time.time())
log.debug(
f"Server {server_jid} marked as unreachable from "
"presence error"
)
except Exception:
log.exception("Can't handle presence error")
def available(self, entity=None, show=None, statuses=None, priority=None):
"""Set a presence and statuses.