-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Prevent ping integration from delaying startup #43869
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
Prevent ping integration from delaying startup #43869
Conversation
Hi @bdraco :) To let the kernel handle some parts of the ICMP headers and thus perform the You should also handle these exceptions:
The complete documentation is up to date. You can find useful information about parameters, return value, and exceptions here: https://github.com/ValentinBELYN/icmplib#ping Finally, the |
We only support WSL for Windows (https://github.com/home-assistant/architecture/blob/master/adr/0016-home-assistant-core.md#supported-operating-systems-and-versions) so I think we can treat it the same as linux in this case. I'll make the adjustments to handle the |
Thanks @ValentinBELYN. Your feedback was very helpful. I think I've addressed the issues. |
It looks like it won't work unless the OS enables it
|
Can you run the following lines to verify that the ping function can run without root privileges on your computer? # Run these lines without root privileges
from icmplib import ping
ping('1.1.1.1', privileged=False) If it doesn't work, can you give me the result you get by running these lines: from icmplib.utils import platform, PLATFORM_LINUX, PLATFORM_MACOS, PLATFORM_WINDOWS
print(platform, PLATFORM_LINUX, PLATFORM_MACOS, PLATFORM_WINDOWS, sep='\n') Thanks :) |
|
|
From the first test
|
What is your Linux distro + version? |
I will investigate tomorrow. Personally on macOS 10.15 and Ubuntu 20.04 I do not encounter this problem. |
Ubuntu 18.04.3 LTS (GNU/Linux 4.4.59+ x86_64) |
I get exactly the same on raspbian 10/buster. |
Sorry for taking some time for testing. I confirm the behavior you are seeing and indeed, this is related to the On Ubuntu 20.04 LTS and later, the value is I added explanations on the project page: https://github.com/ValentinBELYN/icmplib#how-to-use-the-library-without-root-privileges Unfortunately, on operating systems that do not allow this feature by default and to use the library without root privileges, the following command is required: $ sudo sysctl -w net.ipv4.ping_group_range='0 2147483647' On another level, I released the version 2.0.1 to fix old bugs. |
So, would it be possible to keep the drop back to the old method for the time being? Are there any other options? |
Old ping method doesn't work well. What about to create new sensor for old style ping? Currently I'm running patched version of new ping integration with latest HA for couple of days and it work like a charm. |
If you want to remove the fallback, you need to make sure that the operating system allows datagram sockets to use icmplib without root privileges. One solution would be to add the following line to the net.ipv4.ping_group_range='0 2147483647' A restart or the To check the current value: $ sysctl net.ipv4.ping_group_range I don't know why this feature is disabled by default, especially since it doesn't introduce any security breach or compatibility errors. |
@ValentinBELYN it's not issue for me, check here: #43188 (comment) |
I think we can use the unpriv code in more places with the |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
I still need to rework this |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Been testing this for a week with device tracker and binary sensors. Startup only takes ~11s more with it vs multiple minutes before with many binary sensors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @bdraco 👍
Breaking change
When restarting Home Assistant, the previous ping sensor state is now
restored and then updated in the background to allow startup to proceed
without the risk of timing out.
When the user has many ping sensors, the ping integration could
timeout starting up because each ping has to happen in the
executor.
Proposed change
Now that icmplib does not require root for newer kernels, we
can use it if the
can_use_icmp_lib_with_privilege
test passeswith
privileged=False
The startup time problem with ping has been solved by
restoring the previous state instead of waiting for the ping to run
before starting.
NameLookupError
is now handled to avoid the log filling upwhen a host is offline.
device_tracker
now uses multiping when possible to avoidtying up the executor when there are many hosts.
ValentinBELYN/icmplib@v2.0.2...v2.1.1
Type of change
Example entry for
configuration.yaml
:# Example configuration.yaml
Additional information
ping -n -q -c 1 -W1 myhost.mynetwork.lan
, return code: 2" #43785 and fixes Binary ping sensor unavailable after HA (re)start #43188Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: