Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.6 proposal: Fixed HA Deprecation, Error Handling, Resources Management #113

Closed
wants to merge 9 commits into from

Conversation

ms1design
Copy link

@ms1design ms1design commented Mar 19, 2024

Hi @mudape 👋

Added few fixes to ensure proper resource cleanup and prevent resource leaks, ensuring the stability and reliability of the code:

  • Replaced SOURCE_TYPE_ROUTER with SourceType.ROUTER (There is a warning in HA 2024.1b #101).

  • Wrapped the code that might raise exceptions in try-except blocks.

  • Use the closing context manager from the contextlib module to ensure that the IPRoute instance is properly closed after use, even if an exception occurs within the block. The closing context manager ensures that the __exit__ method of the IPRoute instance is always called, allowing it to release any associated resources.

    The IPRoute class from the pyroute2 library interacts with system resources, and not closing instances of it could lead to resource leaks. Each instance of IPRoute may allocate file descriptors for communication with the kernel's netlink subsystem, and if these descriptors are not released, they can accumulate over time, leading to the observed behavior in 2.0.5: Too many open files #99 .

  • If an exception occurs while querying the network state using IPRoute, it's caught and handled gracefully, and a default state value is used instead.

conflict and version is added by github action
@mudape
Copy link
Owner

mudape commented Mar 22, 2024

@ms1design Sorry, I messed stuff up when trying to be quick during the lunchbreak

@ms1design
Copy link
Author

@mudape did you had time to take a look on this one? What's you take on?

@mudape
Copy link
Owner

mudape commented Mar 22, 2024

@ms1design
Yes, looks fine :)
I only have access to my office PC which lacks git and also haven't been keeping up to with this for months..
This lead to me totally breaking your PR
The code you submitted to the branch with me copy/pasting :/

@ms1design
Copy link
Author

No worries chap :) Please ping me in a comment when you will be sorted out with your changes and I can update this PR before merging. @mudape it's better to review PR's first instead of copy-paste ;)

@mudape mudape closed this Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants