Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
## 2024-05-24 - [Thread Pool Size for Concurrent I/O]
**Learning:** Hardcoded, small thread pool limits (like `max_workers=50`) act as severe bottlenecks for highly I/O bound concurrent network tasks like ping sweeping an entire subnet. Because pings spend most of their time waiting on network timeouts, artificially restricting concurrency forces the pool to process timeouts in batches, drastically increasing total scan time.
**Action:** When using `concurrent.futures.ThreadPoolExecutor` for pure I/O or network tasks where the operation is mostly waiting, dynamically size `max_workers` to handle the full workload concurrently (e.g., `min(total_tasks, 256)`) to complete all timeouts in parallel.

## 2024-05-25 - [Reverse DNS Resolution Overhead in Ping]
**Learning:** When utilizing the `ping` command via subprocesses for network scanning, omitting the `-n` flag can lead to significant multi-second delays for each target IP that lacks a PTR record or when DNS servers are unresponsive, due to reverse DNS resolution attempts.
**Action:** Always include the `-n` flag in `ping` commands during network scans to disable reverse DNS resolution, preventing unnecessary delays and speeding up the scan process.
2 changes: 1 addition & 1 deletion test_testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_is_reachable_calls_ping_correctly(self, mock_call):
is_reachable('192.168.1.1', timeout=5)
# Verify that subprocess.call was called with the correct arguments, including the timeout
mock_call.assert_called_once_with(
['ping', '-c', '1', '-W', '5', '192.168.1.1'],
['ping', '-n', '-c', '1', '-W', '5', '192.168.1.1'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=7
)

Expand Down
5 changes: 4 additions & 1 deletion testping1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def is_reachable(ip, timeout=1):
logging.error(f"Invalid timeout value: {repr(timeout)}")
return False

command = ["ping", "-c", "1", "-W", str(timeout_val), str(ip_obj)] # -W for timeout in seconds (Linux)
# ⚑ Bolt: Add `-n` flag to disable reverse DNS resolution.
# This prevents significant multi-second delays when target IPs lack a PTR
# record or DNS servers are unresponsive.
command = ["ping", "-n", "-c", "1", "-W", str(timeout_val), str(ip_obj)] # -W for timeout in seconds (Linux)

# ⚑ Bolt: Optimized ping execution by using subprocess.call and redirecting
# output to DEVNULL instead of using Popen with PIPE.
Expand Down
Loading