New submission from Martin Panter:
Bind method may easily fail on Unix if there is no permission to bind to a
privileged port:
>>> try: TCPServer(("", 80), ...)
... except Exception as err: err
...
PermissionError(13, 'Permission denied')
>>> gc.collect()
__main__:1: ResourceWarning: unclosed <socket.socket fd=3,
family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0,
laddr=('0.0.0.0', 0)>
0
This problem is inherited by HTTPServer and WSGIServer. My current workaround
includes this code in a BaseServer fixup mixin, invoking server_close() if
__init__() fails:
class Server(BaseServer, Context):
def __init__(self, ...):
try:
super().__init__((host, port), RequestHandlerClass)
except: # Workaround for socketserver.TCPServer leaking socket
self.close()
raise
def close(self):
return self.server_close()
----------
components: Library (Lib)
messages: 227017
nosy: vadmium
priority: normal
severity: normal
status: open
title: socketserver.TCPSocket leaks socket to garbage collector if
server_bind() fails
type: resource usage
versions: Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22435>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com