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
socketserver.TCPSocket leaks socket to garbage collector if server_bind() fails #66625
Comments
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() |
Patch attached. |
Patch looks of to me. |
New changeset 437002018d2d by Charles-François Natali in branch '2.7': |
New changeset 9c8016af2ed8 by Charles-François Natali in branch '3.4': New changeset 3bd0f2516445 by Charles-François Natali in branch 'default': |
This is fixed in 3.4.3. I think it can be closed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: