Skip to content

Client resetting a connection results in further exceptions during attempts to clean up #15

@nagisa

Description

@nagisa

If the client such as velbuslink is terminated abnormally, the TCP connection that was made to the python-velbustcp program will be reset by the client’s OS. This will result in execution log along the lines of:

Sep 25 15:28:01 hotbox velbustcp[757498]: 2023-09-25 15:28:01,040 - ERROR - client - Exception during packet receiving
Sep 25 15:28:01 hotbox velbustcp[757498]: Traceback (most recent call last):
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/g1j5114r12n85hm76yndlqbz4zgqjkck-python-velbustcp-c619824/lib/python3.10/site-packages/velbustcp/lib/connection/tcp/client.py", l>
Sep 25 15:28:01 hotbox velbustcp[757498]:     data = self.__connection.socket.recv(1024)
Sep 25 15:28:01 hotbox velbustcp[757498]: ConnectionResetError: [Errno 104] Connection reset by peer
Sep 25 15:28:01 hotbox velbustcp[757498]: 2023-09-25 15:28:01,040 - INFO - client - Closing client connection for ('192.168.110.2', 43860)
Sep 25 15:28:01 hotbox velbustcp[757498]: Exception in thread TCP-RECV: ('192.168.110.2', 43860):
Sep 25 15:28:01 hotbox velbustcp[757498]: Traceback (most recent call last):
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/2c7sgx69p6mmp76cvmi5j6c72dj76jj8-python3-3.10.12/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.run()
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/2c7sgx69p6mmp76cvmi5j6c72dj76jj8-python3-3.10.12/lib/python3.10/threading.py", line 953, in run
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.run()
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/2c7sgx69p6mmp76cvmi5j6c72dj76jj8-python3-3.10.12/lib/python3.10/threading.py", line 953, in run
Sep 25 15:28:01 hotbox velbustcp[757498]:     self._target(*self._args, **self._kwargs)
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/g1j5114r12n85hm76yndlqbz4zgqjkck-python-velbustcp-c619824/lib/python3.10/site-packages/velbustcp/lib/connection/tcp/client.py", l>
Sep 25 15:28:01 hotbox velbustcp[757498]:     self._target(*self._args, **self._kwargs)
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/g1j5114r12n85hm76yndlqbz4zgqjkck-python-velbustcp-c619824/lib/python3.10/site-packages/velbustcp/lib/connection/tcp/client.py", l>
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.stop()
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/g1j5114r12n85hm76yndlqbz4zgqjkck-python-velbustcp-c619824/lib/python3.10/site-packages/velbustcp/lib/connection/tcp/client.py", l>
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.stop()
Sep 25 15:28:01 hotbox velbustcp[757498]:   File "/nix/store/g1j5114r12n85hm76yndlqbz4zgqjkck-python-velbustcp-c619824/lib/python3.10/site-packages/velbustcp/lib/connection/tcp/client.py", l>
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.__connection.socket.shutdown(socket.SHUT_RDWR)
Sep 25 15:28:01 hotbox velbustcp[757498]: OSError: [Errno 107] Transport endpoint is not connected
Sep 25 15:28:01 hotbox velbustcp[757498]:     self.__connection.socket.shutdown(socket.SHUT_RDWR)
Sep 25 15:28:01 hotbox velbustcp[757498]: OSError: [Errno 107] Transport endpoint is not connected

Note that once the connection has been reset, velbustcp will unconditionally attempt to shutdown the connection socket which will again fail with an error.

This does not appear to have impacted the operation of velbustcp much, but it would be neat to handle this case more gracefully (which might very well be a simple try...except block around the shutdown.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions