This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年09月18日 00:25 by martin.panter, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| socketserver_bind_leak.diff | neologix, 2014年09月19日 21:21 | review | ||
| 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)>
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()
|
|||
| 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 changeset 437002018d2d 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 changeset 9c8016af2ed8 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/9c8016af2ed8 New changeset 3bd0f2516445 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 | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:08 | admin | set | github: 66625 |
| 2015年02月27日 02:50:39 | berker.peksag | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2015年02月27日 02:01:42 | martin.panter | set | messages: + msg236723 |
| 2014年10月13日 18:33:10 | python-dev | set | messages: + msg229259 |
| 2014年10月13日 17:43:17 | python-dev | set | nosy:
+ python-dev messages: + msg229256 |
| 2014年09月21日 20:19:38 | pitrou | set | messages:
+ msg227234 versions: + Python 3.5 |
| 2014年09月19日 21:21:36 | neologix | set | files:
+ socketserver_bind_leak.diff nosy: + pitrou, vstinner messages: + msg227126 keywords: + patch stage: patch review |
| 2014年09月18日 13:17:17 | pitrou | set | nosy:
+ neologix |
| 2014年09月18日 00:25:22 | martin.panter | create | |