2 min read
What a port scanner taught me about timeouts.
Every network call is a promise that might never be kept. Plan for that from line one.
PortScannerPro does one simple thing: it tries to open a connection to a list of ports and tells you which ones answered. The interesting part is the ports that do not answer at all.
A closed port usually replies quickly with a refusal. A filtered port often replies with nothing, and a naive scanner will sit there waiting until the operating system gives up, which can take a very long time.
My first version had no explicit timeouts. Scanning a firewalled host took minutes, and the browser tab looked frozen. The fix was obvious in hindsight: every connection attempt gets its own deadline, and the scan reports "no answer" as a real result rather than an error.
That changed how I think about network code everywhere. Every call to another service is a promise that might never be kept. If you do not decide how long you are willing to wait, something else will decide for you, usually at the worst moment.
The second lesson was concurrency. Opening a thousand sockets at once is a good way to get rate-limited or to trip somebody's intrusion detection. A small worker pool with a sensible limit made scans both faster and politer.
The third was reporting. People do not want a wall of port numbers. They want to know whether the thing they meant to expose is reachable and whether anything else is. Grouping results that way did more for the product than any speed improvement.
None of this is new. But building a small tool end to end is the fastest way I know to turn advice you have read into instincts you actually have.