Skip to content

Commit

Permalink
Catch errors on TCP/UDP socket closing to prevent requeuing of events (
Browse files Browse the repository at this point in the history
…#100)

Relates to #98.
  • Loading branch information
eht16 authored Jan 26, 2025
1 parent 7f9a507 commit 8d98346
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions logstash_async/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def _close(self, force=False):
if self._sock:
try:
self._wait_for_socket_buffer_empty()
self._sock.shutdown(socket.SHUT_WR)
self._sock.close()
self._try_to_close_socket()
finally:
self._sock = None

Expand All @@ -162,6 +161,19 @@ def _is_sock_write_buff_empty(self):
buffer_size = struct.unpack('I', ioctl_result)[0]
return not buffer_size

# ----------------------------------------------------------------------
def _try_to_close_socket(self):
try:
self._sock.shutdown(socket.SHUT_WR)
self._sock.close()
except Exception as exc:
self._log_close_socket_error(exc)

# ----------------------------------------------------------------------
def _log_close_socket_error(self, exc):
msg = f'Error on closing the transport socket: {exc}'
logger.warning(msg)

# ----------------------------------------------------------------------
def close(self):
self._close(force=True)
Expand Down

0 comments on commit 8d98346

Please sign in to comment.