Skip to content

close Connection socket after server disconnect#1552

Merged
kovidgoyal merged 1 commit intokovidgoyal:masterfrom
pawl:fix_socket_close
Dec 17, 2021
Merged

close Connection socket after server disconnect#1552
kovidgoyal merged 1 commit intokovidgoyal:masterfrom
pawl:fix_socket_close

Conversation

@pawl
Copy link
Contributor

@pawl pawl commented Dec 17, 2021

This is similar to: redis/redis-py#1797

Currently, calibre/srv/loop.py's Connection.close() won't continue to close the socket if it encounters an OSError on socket.shutdown. An OSError can happen on socket.shutdown if the other side of the connection disconnected already. Not running socket.close prevents garbage collection from cleaning up the socket and will use more memory than necessary (maybe even causing a leak?).

This PR puts a separate try/except around socket.close and socket.shutdown to allow the socket to be closed after a failed shutdown.

@kovidgoyal kovidgoyal merged commit 1127c28 into kovidgoyal:master Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants