2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-29 21:09:32 +00:00

Merge pull request #65 from jjohnson42/handleinflight

Protect against stale data in new requests
This commit is contained in:
chenglch 2017-02-14 15:03:32 +08:00 committed by GitHub
commit 5678942186

View File

@ -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,14 @@ 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:
result = tlvdata.recv(server)
inflight = True
payload = {'operation': operation, 'path': path}
if parameters is not None:
payload['parameters'] = parameters
@ -234,6 +244,7 @@ def send_request(operation, path, server, parameters=None):
while '_requestdone' not in result:
yield result
result = tlvdata.recv(server)
inflight = False