prevent event loop polling on closed redis transports (and causing leak) #1476
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is related to my comment on the celery memory leak bug: celery/celery#4843 (comment)
I added some logging to
on_poll_startin the redisTransport'sregister_with_event_loop, and I noticed the event loop continues to poll on redisTransports that were disconnected. This causes some leftover references to the initializedTransportin the event loop'son_tickand prevents the initializedTransportfrom being garbage collected.This is similar to the issue @michael-lazar noticed in bug #1 in his comment about the py-amqp memory leak. However, the code for the redis transport is very different because it uses
MultiChannelPoller.This PR fixes the issue by removing the disconnected redis
Transport's polling function from the event loop'son_tickwhen disconnection occurs (to stop the polling in the event loop on the dead Transport).I tested the fix with this minimal example and was able to confirm it stopped the relevant memory leak.