Skip to content

Commit 85a4fcc

Browse files
brubbeloroulet
authored andcommitted
fix OSError: [Errno 9] Bad file descriptor
Gracefully handle a client.disconnect() when the underlying socket is already closed. cfr. #741
1 parent e318a4e commit 85a4fcc

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

opcua/client/ua_client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ def close_secure_channel(self):
193193
"""
194194
self.logger.info("close_secure_channel")
195195
request = ua.CloseSecureChannelRequest()
196-
future = self._send_request(request, message_type=ua.MessageType.SecureClose)
197-
with self._lock:
198-
# don't expect any more answers
199-
future.cancel()
200-
201-
# some servers send a response here, most do not ... so we ignore
196+
try:
197+
future = self._send_request(request, message_type=ua.MessageType.SecureClose)
198+
with self._lock:
199+
# some servers send a response here, most do not ... so we ignore
200+
future.cancel()
201+
except OSError as exc:
202+
raise
203+
if exc.errno == errno.EBADF:
204+
pass # Socket is closed, so can't send SecureClose request.
205+
else:
206+
raise
202207

203208
def is_secure_channel_open(self):
204209
return self._connection.is_open()

0 commit comments

Comments
 (0)