I'm working on a Twisted-based application where a memory leak occurs when a connection fails. The transport object continues to hold references, preventing garbage collection.
After a failed connection, I observe lingering references in memory, such as:
[{'_tempDataBuffer': [], 'protocol': None, 'addr': ('127.0.0.1', 12035), '_tempDataLen': 0, 'realAddress': ('127.0.0.1', 12035), 'doRead': <bound method Client.doConnect of <<class 'twisted.internet.tcp.Client'> to ('127.0.0.1', 12035) at 0x7f639f618350>>, 'doWrite': <bound method Client.doConnect of <<class 'twisted.internet.tcp.Client'> to ('127.0.0.1', 12035) at 0x7f639f618350>>, '_requiresResolution': False, 'reactor': <twisted.internet.epollreactor.EPollReactor object at 0x7f639fabe6d0>}]
It appears that doRead and doWrite are bound methods, keeping references alive. Additionally, the transport might still be present in the reactor’s reader/writer list.
What I've Tried: Calling loseConnection() on the transport when the connection fails.
Setting connector.transport = None inside clientConnectionFailed().
Ensuring the transport is removed from the reactor.
Running gc.collect() manually after connection failure.
However, the memory leak persists, and references to twisted.internet.tcp.Client objects are still present.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743753411a4501320.html
评论列表(0条)