UDP has no handshake, so how do you tell an open port from a dead one?
Dialing a UDP port always succeeds, so a naive check says every port is up. How to get a real answer: send a request the service replies to, and catch ICMP port unreachable on a connected socket.
· 3 min read · By the Spot Downtime team
My first UDP check reported every port on the internet as up, including ones with nothing listening. The reason is one line of Go:
conn, err := net.Dial("udp", "example.com:27015") // err is nil for any host and portA UDP “dial” sends nothing. It picks a local port and remembers where to send. With no handshake, silence from a port looks the same whether the service is fine, dead, behind a firewall, or the packet got lost.
The only proof is a reply
So the check can't just knock. It sends a request the service will answer, and counts the port as up only when a reply comes back containing the bytes you expect. Some that work:
- NTP (port 123): the byte
1bfollowed by 47 zero bytes. Any NTP server answers with the time. - Source game servers: the A2S_INFO query,
FF FF FF FF 54thenSource Engine Queryand a null byte. Require only theFF FF FF FFprefix, because newer servers reply with a challenge first. - Your own service: whatever ping or status message it already answers.
Closed ports can fail in milliseconds
Waiting for a reply means a dead service costs a full timeout. But when a packet reaches a host with nothing on that port, the host usually sends back ICMP “port unreachable”. Whether your program ever hears about it depends on the socket:
connected socket (net.Dial) unconnected socket (net.ListenPacket)
Write -> packet to host:port WriteTo -> packet to host:port
<- ICMP port unreachable <- ICMP port unreachable
Read -> ECONNREFUSED, right away ReadFrom -> waits until the timeoutOn a connected socket the kernel matches the ICMP error to it and returns it from the next call. So the check writes first, then reads, and tells the two failures apart:
n, err := conn.Read(buf)
switch {
case errors.Is(err, syscall.ECONNREFUSED):
res.Error = "port closed (ICMP port unreachable)"
case isTimeout(err):
res.Error = "no reply within 10s"
}“Port closed” means the host is up and your service isn't running. “No reply” means something dropped the packets or the service is hung. Different problems, different fixes.
Silence still isn't proof
Firewalls drop ICMP and hosts rate-limit it, so a closed port can look exactly like a lost packet. A single missed reply shouldn't page anyone: the check is retried and confirmed from a second region before an incident opens.
Have a real protocol? Check that instead
In short
- Over UDP, a port is up only if it answers.
- Use a connected socket, so closed ports fail fast instead of timing out.
- Confirm a timeout before you alert.
I wrote this while building UDP checks for Spot Downtime.
Get new guides by email
Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.
Keep reading
- Monitoring · Servers · UptimeKubernetes liveness and readiness probes vs external uptime monitoringProbes keep pods healthy inside the cluster. They can't tell you users can't reach the site. How liveness, readiness and startup probes work, and what to add outside.November 15, 2026 · 7 min read
- Monitoring · Uptime · AlertsHow often should an uptime monitor check your site?Check interval decides how long an outage goes unnoticed. How to pick between 30 seconds, 1 minute and 5 minutes, and which services deserve the faster setting.November 14, 2026 · 6 min read