Skip to content

Commit e93a8e4

Browse files
committed
session: Don't fail shutdown() on spurious errors
On MacOS we can see OSError ENOTCONN generated by socket.shutdown(). Ignore these exceptions.
1 parent 7cd471b commit e93a8e4

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

pynuodb/session.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,17 @@ def __readFully(self, msgLength, timeout=None):
429429

430430
def close(self, force=False):
431431
""" Close the current socket connection with the server """
432-
if not self.__sock:
432+
if self.__sock is None:
433433
return
434434

435435
try:
436436
if force:
437-
self.__sock.shutdown(socket.SHUT_RDWR)
438-
439-
if self.__sock:
440-
self.__sock.close()
437+
try:
438+
self.__sock.shutdown(socket.SHUT_RDWR)
439+
except (OSError, socket.error):
440+
# On MacOS this can raise "Socket is not connected"
441+
pass
442+
self.__sock.close()
441443
finally:
442444
self.__sock = None
443445

0 commit comments

Comments
 (0)