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:
q("INSERT OR REPLACE INTO peer VALUES (?,?)", (prefix, address))
q("INSERT OR REPLACE INTO volatile.stat VALUES (?,0)", (prefix,))
def getCountry(self, ip: str) -> str:
def getCountry(self, ip: str) -> str | None:
try:
return self._registry.getCountry(self._prefix, ip).decode()
except socket.error as e:
logging.warning('Failed to get country (%s)', ip)
country = self._registry.getCountry(self._prefix, ip)
if country is not None:
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