From ffbe1ab1561ef29375c025e7c141128cc23defd9 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 10 Feb 2017 11:20:39 -0500 Subject: [PATCH 1/2] Protect against stale data in new requests If a caller (reasonably) broke out of a loop, a subsequent call would get old data. Protect against this by discarding data not consumed if previously called. --- confluent_client/confluent/client.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index aa30e6a1..f3c91225 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -27,6 +27,8 @@ import confluent.tlvdata as tlvdata SO_PASSCRED = 16 +inflight = False + def _parseserver(string): if ']:' in string: server, port = string[1:].split(']:') @@ -226,6 +228,15 @@ def send_request(operation, path, server, parameters=None): :param server: The socket to send data over :param parameters: Parameters if any to send along with the request """ + global inflight + if inflight: + # calling code failed to complete a transaction, flush and discard + # their unused data + result = tlvdata.recv(server) + while '_requestdone' not in result: + yield result + result = tlvdata.recv(server) + inflight = True payload = {'operation': operation, 'path': path} if parameters is not None: payload['parameters'] = parameters @@ -234,6 +245,7 @@ def send_request(operation, path, server, parameters=None): while '_requestdone' not in result: yield result result = tlvdata.recv(server) + inflight = False From 583e3474ac8bda4164cd432e1c1b819e8006e1d1 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 10 Feb 2017 11:37:56 -0500 Subject: [PATCH 2/2] Do not yield data to discard --- confluent_client/confluent/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index f3c91225..07a85423 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -234,7 +234,6 @@ def send_request(operation, path, server, parameters=None): # their unused data result = tlvdata.recv(server) while '_requestdone' not in result: - yield result result = tlvdata.recv(server) inflight = True payload = {'operation': operation, 'path': path}