Skip to content

Commit

Permalink
Flush the buffer on corrupt data
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorsington committed Dec 16, 2018
1 parent 97748b2 commit a61ecdb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion GUI/maidfiddler/util/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, on_connection_lost):
self.handler = None
self.call_id = 0
self.on_connection_lost = on_connection_lost
self.max_retries = 5

def connect(self, pipe_name):
self.handler = open(f"\\\\.\\pipe\\{pipe_name}", "r+b", 0)
Expand Down Expand Up @@ -61,6 +62,9 @@ def __call__(self, method, *args, **kargs):
return result

def try_invoke(self, method, *args):
return self._try_invoke_internal(method, 1, *args)

def _try_invoke_internal(self, method, try_count, *args):
if isinstance(method, bytes):
method = method.decode('utf-8')
print(f"Calling {method}")
Expand Down Expand Up @@ -93,7 +97,15 @@ def try_invoke(self, method, *args):
self.close()
return (None, True)

response = msgpack.unpackb(response_packed, raw=False)
try:
response = msgpack.unpackb(response_packed, raw=False)
except msgpack.ExtraData as e:
if try_count >= self.max_retries:
print(f"Forcing to fail after {try_count} tries.")
return (None, True)
print(f"Received extra data! Flushing and retrying. More info: {e}")
self._flush()
return self._try_invoke_internal(method, try_count + 1, *args)

response_type = response["data"][0]

Expand Down

0 comments on commit a61ecdb

Please sign in to comment.