Skip to content

Commit

Permalink
Fix: a compatibility problem with previous version.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Grégory Starck committed Nov 18, 2014
1 parent 467151c commit 52f33aa
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions module/livestatus_client_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52f33aa

Please sign in to comment.