Skip to content

Commit 998d798

Browse files
authored
Merge pull request #60 from launchdarkly/dr/eventErrors
Add more defensive checks when sending events
2 parents e4a149c + 491e1b9 commit 998d798

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ldclient/event_consumer.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def run(self):
2626
log.info("Starting event consumer")
2727
self._running = True
2828
while self._running:
29-
self.send()
29+
try:
30+
self.send()
31+
except Exception:
32+
log.exception(
33+
'Unhandled exception in event consumer')
3034

3135
def stop(self):
3236
self._running = False
@@ -53,11 +57,12 @@ def do_send(should_retry):
5357
data=json_body)
5458
r.raise_for_status()
5559
except ProtocolError as e:
56-
inner = e.args[1]
57-
if inner.errno == errno.ECONNRESET and should_retry:
58-
log.warning(
59-
'ProtocolError exception caught while sending events. Retrying.')
60-
do_send(False)
60+
if e.args is not None and len(e.args) > 1 and e.args[1] is not None:
61+
inner = e.args[1]
62+
if inner.errno is not None and inner.errno == errno.ECONNRESET and should_retry:
63+
log.warning(
64+
'ProtocolError exception caught while sending events. Retrying.')
65+
do_send(False)
6166
else:
6267
log.exception(
6368
'Unhandled exception in event consumer. Analytics events were not processed.')

0 commit comments

Comments
 (0)