Scenario
A web-scraper systemd service is running on this system, making continuous HTTP requests. The service has started experiencing connection failures - logs show HTTP status 000 errors, indicating connections cannot be established even though the network is functional and remote servers are accessible.
Task
Check the service status and logs to understand the failures, investigate the underlying cause, identify which system resource is exhausted, apply the appropriate kernel configuration change.
Once fix is applied you can test the connection with curl -o /dev/null -s -w "HTTP Status: %{http_code}\n" http://example.com
Step 1: View the service logs to see the errors
sudo journalctl -u web-scraper -n 50
Shows the last 50 log entries. You should see repeated "HTTP 000" connection failures indicating the actual problem.
Step 2: Check the current number of TIME_WAIT sockets
ss -tan state time-wait | wc -l
This counts how many TCP connections are in TIME_WAIT state.
Step 3: View detailed TIME_WAIT socket information
ss -tan state time-wait | head -20
Shows the first 20 TIME_WAIT connections to understand the pattern.
Step 4: Check the ephemeral port range
sysctl net.ipv4.ip_local_port_range
Shows the range of ports available for outbound connections (e.g., 32768-60999).
Step 5: Check the current tcp_tw_reuse setting
sysctl net.ipv4.tcp_tw_reuse
Shows whether TIME_WAIT socket reuse is enabled (0=disabled, 1=enabled).
Step 6: Enable tcp_tw_reuse
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
This applies the change immediately.
Step 7: Test the scraper or create test connections
curl -o /dev/null -s -w "HTTP Status: %{http_code}\n" http://example.com
Verify that outbound connections now succeed without "Cannot assign requested address".
Step 8: Monitor TIME_WAIT socket reuse during operation
ss -tan state time-wait | wc -l