最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - Twisted: Memory Leak on Connection Failure - Transport Object Holding References - Stack Overflow

matteradmin4PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far