Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue22435

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:socketserver.TCPSocket leaks socket to garbage collector if server_bind() fails
Type:resource usageStage:resolved
Components:Library (Lib)Versions:Python 3.4, Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: martin.panter, neologix, pitrou, python-dev, vstinner
Priority:normalKeywords:patch

Created on2014-09-18 00:25 bymartin.panter, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
socketserver_bind_leak.diffneologix,2014-09-19 21:21review
Messages (6)
msg227017 -(view)Author: Martin Panter (martin.panter)*(Python committer)Date: 2014-09-18 00:25
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)>0This 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()
msg227126 -(view)Author: Charles-François Natali (neologix)*(Python committer)Date: 2014-09-19 21:21
Patch attached.The test wouldn't result in FD exhaustion on CPython because of the reference counting, but should still trigger RessourceWarning.
msg227234 -(view)Author: Antoine Pitrou (pitrou)*(Python committer)Date: 2014-09-21 20:19
Patch looks of to me.
msg229256 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-10-13 17:43
New changeset437002018d2d by Charles-François Natali in branch '2.7':Issue#22435: Fix a file descriptor leak when SocketServer bind fails.https://hg.python.org/cpython/rev/437002018d2d
msg229259 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-10-13 18:33
New changeset9c8016af2ed8 by Charles-François Natali in branch '3.4':Issue#22435: Fix a file descriptor leak when SocketServer bind fails.https://hg.python.org/cpython/rev/9c8016af2ed8New changeset3bd0f2516445 by Charles-François Natali in branch 'default':Issue#22435: Fix a file descriptor leak when SocketServer bind fails.https://hg.python.org/cpython/rev/3bd0f2516445
msg236723 -(view)Author: Martin Panter (martin.panter)*(Python committer)Date: 2015-02-27 02:01
This is fixed in 3.4.3. I think it can be closed.
History
DateUserActionArgs
2022-04-11 14:58:08adminsetgithub: 66625
2015-02-27 02:50:39berker.peksagsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-02-27 02:01:42martin.pantersetmessages: +msg236723
2014-10-13 18:33:10python-devsetmessages: +msg229259
2014-10-13 17:43:17python-devsetnosy: +python-dev
messages: +msg229256
2014-09-21 20:19:38pitrousetmessages: +msg227234
versions: + Python 3.5
2014-09-19 21:21:36neologixsetfiles: +socketserver_bind_leak.diff

nosy: +pitrou,vstinner
messages: +msg227126

keywords: +patch
stage: patch review
2014-09-18 13:17:17pitrousetnosy: +neologix
2014-09-18 00:25:22martin.pantercreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp