Commit ee2db2f4 authored by Julien Muchembled's avatar Julien Muchembled

Fix possible crash when asking the registry to geo-locate an ip

This fixes a regression in commit 6ac47ffb.
parent 5e2a7145
Pipeline #39417 passed with stage
in 0 seconds
...@@ -269,8 +269,10 @@ class Cache: ...@@ -269,8 +269,10 @@ class Cache:
q("INSERT OR REPLACE INTO peer VALUES (?,?)", (prefix, address)) q("INSERT OR REPLACE INTO peer VALUES (?,?)", (prefix, address))
q("INSERT OR REPLACE INTO volatile.stat VALUES (?,0)", (prefix,)) q("INSERT OR REPLACE INTO volatile.stat VALUES (?,0)", (prefix,))
def getCountry(self, ip: str) -> str: def getCountry(self, ip: str) -> str | None:
try: try:
return self._registry.getCountry(self._prefix, ip).decode() country = self._registry.getCountry(self._prefix, ip)
except socket.error as e: if country is not None:
logging.warning('Failed to get country (%s)', ip) return country.decode()
except (socket.error, UnicodeDecodeError) as e:
logging.warning('Failed to get country for %s (%s)', ip, e)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment