Commit a67641e6 authored by Vitaly Lipatov's avatar Vitaly Lipatov

gateway: skip malformed Redis messages

parent 4cfb9f45
...@@ -440,7 +440,7 @@ restore_bans_from_redis() ...@@ -440,7 +440,7 @@ restore_bans_from_redis()
load_whitelist() load_whitelist()
def process_message(message): def process_message_inner(message):
if message is not None and message['type']=='message' and message['channel'] == b'ban': if message is not None and message['type']=='message' and message['channel'] == b'ban':
ip = message['data'].decode('utf-8') ip = message['data'].decode('utf-8')
ipo = ipaddress.ip_address(ip) ipo = ipaddress.ip_address(ip)
...@@ -531,6 +531,14 @@ def process_message(message): ...@@ -531,6 +531,14 @@ def process_message(message):
pass pass
def process_message(message):
"""Handle malformed Pub/Sub payloads without losing the subscription."""
try:
process_message_inner(message)
except (KeyError, TypeError, UnicodeDecodeError, ValueError) as error:
log_redis_error("Invalid Redis message skipped: " + str(error) + "; payload=" + repr(message)[:200])
while True: while True:
try: try:
for message in p.listen(): for message in p.listen():
......
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