Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible AttributeError and OSError on calling TCPTransport.close() #438

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions erpc_python/erpc/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self, host, port, isServer):
self._port = port
self._isServer = isServer
self._sock = None
self._socket_lock = threading.Lock()

if self._isServer:
self._serverThread = threading.Thread(target=self._serve)
Expand All @@ -170,9 +171,17 @@ def _serve(self):
def close(self):
if self._isServer:
self._serverSockEventStart.clear()
self._sock.shutdown(SHUT_RDWR)
self._sock.close()
self._sock = None

with self._socket_lock:
if self._sock is not None:
try:
self._sock.shutdown(SHUT_RDWR)
self._sock.close()
except OSError:
# May be raised by the OS if the socket was closed externally,
# thus invalidating the file descriptor.
pass
self._sock = None

def _base_send(self, message):
if self._isServer:
Expand Down