From 52f33aad8420ba191dc853b63dc9d84fb6674a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Starck?= Date: Tue, 18 Nov 2014 14:30:49 -0500 Subject: [PATCH] Fix: a compatibility problem with previous version. If we receive an incomplete query and then the client close its write side, then still process the query (even if incomplete) : the client can still be waiting for the response. --- module/livestatus_client_thread.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/module/livestatus_client_thread.py b/module/livestatus_client_thread.py index 98a281a..8133e5a 100644 --- a/module/livestatus_client_thread.py +++ b/module/livestatus_client_thread.py @@ -11,6 +11,7 @@ import traceback from shinken.log import logger + from .livestatus_obj import LiveStatus from .livestatus_response import LiveStatusListResponse from .livestatus_query_error import LiveStatusQueryError @@ -109,15 +110,26 @@ def read_request(self): if exceptready: raise Error.client_error if inputready: - data = self._read() - if data: - self.buffer_list.append(data) - if self._has_query(): - self.last_query_time = time.time() - full_request = b''.join(self.buffer_list) + try: + data = self._read() + except Error.ClientLeft: + # very special case : if we already got some data, + if self.buffer_list and self.buffer_list[-1][-1] == '\n': + # then try to consider it as a valid query + self.logger.warn("Have a query not fully terminated but input closed by remote side.. " + "Let's consider this as a valid query and try process it..") + ret = b''.join(self.buffer_list) del self.buffer_list[:] - return full_request - continue + return ret + raise # otherwise simply let the ClientLeft propagate. + + self.buffer_list.append(data) + if self._has_query(): + self.last_query_time = time.time() + full_request = b''.join(self.buffer_list) + del self.buffer_list[:] + return full_request + continue if time.time() > timeout_time: raise Error.ClientTimeout('Timeout reading full request from client') timeout_time += self.read_timeout