From be8d82c6c1bfab238ca32543dcca61f7b68cf121 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 21 Oct 2015 10:22:49 -0400 Subject: [PATCH 1/2] Client behavior fix when server sends 0 data If the server sends zero data, client could hang as it does recv(0). Fix this by returning None in that scenario. --- confluent_client/confluent/tlvdata.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/confluent_client/confluent/tlvdata.py b/confluent_client/confluent/tlvdata.py index 4da3ae38..356a4ee0 100644 --- a/confluent_client/confluent/tlvdata.py +++ b/confluent_client/confluent/tlvdata.py @@ -76,6 +76,8 @@ def recv(handle): # 4 byte tlv dlen = tl & 16777215 # grab lower 24 bits datatype = (tl & 2130706432) >> 24 # grab 7 bits from near beginning + if dlen == 0: + return None data = handle.recv(dlen) while len(data) < dlen: ndata = handle.recv(dlen - len(data)) From 52aaeef506f35814f458be5c45be1abf888bb726 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 21 Oct 2015 10:30:41 -0400 Subject: [PATCH 2/2] Have server avoid sending empty data While the client can handle it now, have the server avoid needless processing of '' data from a console provider. Address it at the deepest level (the tlvdata implementation) and a place higher up the stack to avoid hits to log and such. --- confluent_client/confluent/tlvdata.py | 3 +++ confluent_server/confluent/consoleserver.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/confluent_client/confluent/tlvdata.py b/confluent_client/confluent/tlvdata.py index 356a4ee0..5a13f901 100644 --- a/confluent_client/confluent/tlvdata.py +++ b/confluent_client/confluent/tlvdata.py @@ -38,6 +38,9 @@ def send(handle, data): if isinstance(data, str): # plain text, e.g. console data tl = len(data) + if tl == 0: + # if you don't have anything to say, don't say anything at all + return if tl < 16777216: # type for string is '0', so we don't need # to xor anything in diff --git a/confluent_server/confluent/consoleserver.py b/confluent_server/confluent/consoleserver.py index 37a70161..0e0bdeaa 100644 --- a/confluent_server/confluent/consoleserver.py +++ b/confluent_server/confluent/consoleserver.py @@ -347,6 +347,9 @@ class _ConsoleHandler(object): if data == conapi.ConsoleEvent.Disconnect: self._got_disconnected() return + elif data == '': + # ignore empty strings from a cconsole provider + return if '\x1b[?1l' in data: # request for ansi mode cursor keys self.appmodedetected = False if '\x1b[?1h' in data: # remember the session wants the client to use