Repository navigation
fix(ports): send the ICMP timeout in the unit each ping expects - #3677
Merged
nicolargo merged 1 commit intoAug 26, 2026
Merged
Conversation
Two problems on the same argument.
Windows 'ping -w' is a per-reply timeout in **milliseconds**, not
seconds, so a configured 'timeout = 3' became a 3 ms deadline. Measured
against two hosts that answer well within 3 seconds:
200.160.2.3 (350 ms) ping -n 1 -w 3 -> exit 1
200.160.2.3 (350 ms) ping -n 1 -w 3000 -> exit 0
139.130.4.5 (168 ms) ping -n 1 -w 3 -> exit 1
139.130.4.5 (168 ms) ping -n 1 -w 3000 -> exit 0
Windows clamps the wait to about 50 ms, so a host on the LAN still
answers in time and the bug hides; anything further away is reported
offline. Multiply by 1000 on Windows and leave -W/-t in seconds.
The timeout was also passed through _resolv_name(), which runs
socket.gethostbyname() on it. It is a number of seconds, not a host: the
lookup can only fail, and it logs a misleading 'Cannot convert 3 to IP
address' on every ICMP check.
Owner
|
Thanks for the PR @ntdatt812 I hate Windows :) Merged into develop ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Windows: the timeout is a thousand times too small
_port_scan_icmp()passes the configured timeout straight toping:Windows
ping -wis documented as "Timeout in milliseconds to wait for each reply".-W(Linux) and-t(macOS/BSD) are in seconds. Sotimeout = 3— the default inglances.conf— becomes a 3 ms deadline on Windows.Measured on Windows 11, two hosts that answer comfortably inside 3 seconds:
ping -n 1 -w 3ping -n 1 -w 3000A non-zero exit lands in
port['status'] = False, i.e. the host shows as offline.Windows clamps the actual wait to roughly 50 ms, which is why this hides on a LAN:
So
8.8.8.8at 35 ms still answers in time, and anything further away is silently reported down. That matches the symptom of remote hosts flapping to offline on Windows while the same config is fine on Linux.The same argument also goes through the DNS resolver
_resolv_name()runssocket.gethostbyname(). The timeout is a number of seconds, not a host —ports_list.pybuilds it withint(...), so the call can only raise:_resolv_nameswallows that and returns the value unchanged, so nothing breaks today — but every ICMP check pays for a pointless call and writes a misleadingCannot convert 3 to IP addressinto the debug log.The fix
Build the timeout argument next to the option that consumes it, in that option's own unit, and stop routing it through the resolver.
-Wand-tkeep passing seconds through unchanged.Tests
Four cases added to
tests/test_plugin_ports.py, drivingThreadScanner._port_scan_icmpwithsubprocess.check_callcaptured:['ping', '-n', '1', '-w', '3000', 'example.net']['ping', '-c', '1', '-W', '3', 'example.net']['ping', '-c', '1', '-t', '3', 'example.net']_resolv_nameMutation-checked — reverting the source turns exactly the two affected cases red and leaves the two passthrough cases green:
ruff checkandruff format --checkclean.