[202205] Fix epoll and socket resource leak issue. (#651) #741
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.
Cherry-picking this #651 for 202205 branch.
Why I did it
Fix epoll and socket resurce leak issue:
[chassis] Too many open files error and unable to connect to redis socket error sonic-net/sonic-buildimage#10870
The reason of this issue is in SWIG any method return a new object need decorate with %newobject, so SWIG will generate code to release C++ object when python wrapper object released: https://www.swig.org/Doc4.0/SWIGDocumentation.html#Customization_ownership
How I did it
Update swsscommon.i to decorate return new object methods with %newobject
How to verify it
Pass all test case.
Run following code in python and validate there is no epoll and socket leak:
from swsscommon.swsscommon import SonicDBConfig
from swsscommon.swsscommon import SonicV2Connector import gc
SonicDBConfig.load_sonic_global_db_config()
SonicDBConfig.get_ns_list()
db = SonicV2Connector(use_unix_socket_path=True, namespace='') db.connect("CONFIG_DB")
db.get_redis_client("CONFIG_DB")
client = db.get_redis_client("CONFIG_DB")
client.pubsub()
client.pubsub()
client.pubsub()
client.newConnector(0)
client.newConnector(0)
client.newConnector(0)
gc.collect()
Which release branch to backport (provide reason below if selected)
Description for the changelog
Fix epoll and socket resurce leak issue:
[chassis] Too many open files error and unable to connect to redis socket error sonic-net/sonic-buildimage#10870
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)