[New-bugs-announce] [issue22351] NNTP constructor exception leaves socket for garbage collector

Martin Panter report at bugs.python.org
Sun Sep 7 06:07:08 CEST 2014


New submission from Martin Panter:

If the nntplib.NNTP constructor fails, it often leaves the connection and socket open until the garbage collector cleans them up and emits a ResourceWarning:

>>> try:
...     NNTP("localhost")
... except Exception as err:
...     print(repr(err))
... 
NNTPTemporaryError('400 Service temporarily unavailable',)
>>> gc.collect()
__main__:1: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 54819), raddr=('127.0.0.1', 119)>
12

This happens both for error responses that are expected by the protocol, e.g. service unavailable as above, authentication errors. It also happens for other exceptions such as EOFError if the connection is closed with no response.

----------
components: Library (Lib)
messages: 226528
nosy: vadmium
priority: normal
severity: normal
status: open
title: NNTP constructor exception leaves socket for garbage collector
type: resource usage
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22351>
_______________________________________


More information about the New-bugs-announce mailing list