Skip to content

Commit 50a6399

Browse files
committed
fix(PAR-17098): Devo Python SDK causes log messages to be dropped
1 parent 5e757e5 commit 50a6399

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [3.6.5] - 2023-01-27
8+
### Fixed
9+
* Ingestion endpoint has an inactivity timeout that when reached closes the connection. `devo-sdk` is aware of such a timeout and restart connection before is reached. New parameter `inactivity_timeout` in class `Sender` to set up it. Its default value is 30 seconds.
10+
11+
712
## [3.6.4] - 2022-07-21
813
### Fixed
914
* Fixed bug when processing keep alive empty tokens

devo/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__description__ = 'Devo Python Library.'
22
__url__ = 'http://www.devo.com'
3-
__version__ = "3.6.4"
3+
__version__ = "3.6.5"
44
__author__ = 'Devo'
55
__author_email__ = 'support@devo.com'
66
__license__ = 'MIT'

devo/sender/data.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,12 @@ class Sender(logging.Handler):
286286
:param con_type: TCP or SSL, default SSL, you can pass it in
287287
config object too
288288
:param timeout: timeout for socket
289+
:param inactivity_timeout: inactivity timeout for Ingestion balancer, so connection is restarted before reaching
289290
:param debug: For more info in console/logger output
290291
:param logger: logger. Default sys.console
291292
"""
292-
def __init__(self, config=None, con_type=None,
293+
294+
def __init__(self, config=None, con_type=None, inactivity_timeout=30,
293295
timeout=30, debug=False, logger=None):
294296
if config is None:
295297
raise DevoSenderException("Problems with args passed to Sender")
@@ -298,7 +300,9 @@ def __init__(self, config=None, con_type=None,
298300
self.reconnection = 0
299301
self.debug = debug
300302
self.socket_timeout = timeout
303+
self.inactivity_timeout = inactivity_timeout
301304
self.socket_max_connection = 3600 * 1000
305+
self.last_message = int(time.time())
302306
self.buffer = SenderBuffer()
303307
self.logging = {}
304308

@@ -344,6 +348,7 @@ def __connect_tcp_socket(self):
344348
self.socket.settimeout(self.socket_timeout)
345349
try:
346350
self.socket.connect(self._sender_config.address)
351+
self.last_message = int(time.time())
347352
except socket.error as error:
348353
self.close()
349354
raise DevoSenderException(
@@ -407,6 +412,7 @@ def __connect_ssl(self):
407412
raise ssl.SSLError
408413

409414
self.socket.connect(self._sender_config.address)
415+
self.last_message = int(time.time())
410416
self.reconnection += 1
411417
if self.debug:
412418
self.logger.debug('Conected to %s|%s'
@@ -511,6 +517,13 @@ def __status(self):
511517
if self.socket_max_connection < timeit:
512518
self.close()
513519
return False
520+
521+
# If there is no activity (connection or message sent) for an amount of time bigger then the inactivity
522+
# timeout, the balancer may have already close the connection. Close it and reconnect.
523+
if int(time.time()) - self.last_message > self.inactivity_timeout:
524+
self.close()
525+
return False
526+
514527
return True
515528

516529
def close(self):
@@ -553,6 +566,7 @@ def __send_oc(self, record):
553566
for iteration in range(0, total):
554567
part = record[int(iteration * 4096):
555568
int((iteration + 1) * 4096)]
569+
self.last_message = int(time.time())
556570
if self.socket.sendall(part) is not None:
557571
raise DevoSenderException("Send error")
558572
sent += len(part)
@@ -577,6 +591,7 @@ def send_raw(self, record, multiline=False, zip=False):
577591
if not multiline and not zip:
578592
msg = self.__encode_record(record)
579593
sent = len(msg)
594+
self.last_message = int(time.time())
580595
if self.socket.sendall(msg) is not None:
581596
raise DevoSenderException("Send error")
582597
return 1

docs/sender/data.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Variable descriptions
1414
+ config **(_SenderConfigSSL_, _SenderConfigTCP_ or _dict_)**: address, port, keypath, chainpath, etc
1515
+ con_type **(_string_)**: TCP or SSL, default SSL, you can pass it in config object too
1616
+ timeout **(_int_)**: timeout for socket
17+
+ inactivity_timeout **(_int_)**: inactivity timeout for Ingestion balancer, so connection is restarted before reaching
1718
+ debug **(_bool_)**: True or False, for show more info in console/logger output
1819
+ logger **(_string_)**: logger. Default sys.console
1920

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ click==8.1.3
22
PyYAML==6.0
33
requests==2.27.1
44
pem==21.2.0
5-
pyopenssl==22.0.0
5+
pyopenssl==22.1.*
66
urllib3>=1.26.5

0 commit comments

Comments
 (0)