Cheat sheet · Computer Networking for Developers: IP, TCP, DNS, HTTP and TLS
Networking for Developers cheat sheet
How a request travels from fetch() to res.end(): layers, IP, TCP, DNS, HTTP, TLS, proxies, live connections, and the tools to debug each step. Debug one layer at a time, from the bottom up.
Every byte is numbered. Lost data is resent on a timer that doubles (0.2, 0.4, 0.8 s).
TCP is a byte stream: three sends can arrive as one recv. Frame messages yourself (length prefix).
Flow control = receiver's window (zero window: sender stops). Congestion control = sender's window, a sawtooth; full queues cause bufferbloat.
State / error
Meaning
Refused
RST at once: nothing listens (exit 7)
Timed out
Silence: firewall drops the SYN (exit 28)
TIME_WAIT
Normal on the side that closed first, 60 s
CLOSE_WAIT
Peer closed, your code did not: a bug
Watch out: Always set connect, read and total timeouts: OS defaults take minutes (tcp_retries2 15 is about 15 min). UDP has no resend, order or error; 41 of 100 datagrams vanished silently.
Text over TCP; one answer at a time; browsers open about 6 connections
2
Binary frames, streams, HPACK on one connection; TCP still blocks all
3 (QUIC)
UDP, per-stream order, TLS 1.3 built in, connection migration
12 requests of 300 ms: 3.6 s on one HTTP/1.1 connection, 0.32 s on HTTP/2. HPACK cut headers from 548 to 42 bytes.
HTTP/2 is chosen by ALPN in the TLS handshake. HTTP/3 is learned from Alt-Svc. Keep HTTP/2 working; UDP can be blocked.
HTTP/2 headers are lowercase, :authority replaces Host, no Connection header.
0-RTT can be replayed: allow it only for safe GETs.
Watch out: Random ECONNRESET on idle keep-alive: the server closed first. Keep the client idle timeout shorter than the server and load balancer (Node default 5 s). Retry idempotent calls once.
TLS gives confidentiality, integrity and authentication. TLS 1.3 costs one round trip after TCP and gives forward secrecy.
Client checks: chain to a trusted root, dates, name in SAN, key usage. The server must send the intermediate.
SNI (host name) is plain text; TLS 1.3 encrypts the certificate. HTTPS still shows the IP and host.
Let's Encrypt: HTTP-01 needs port 80, no wildcard. DNS-01 uses a TXT at _acme-challenge, allows wildcards. Certs are 90 days or less: automate and alert 14 days ahead.
Error
Usual cause
UNABLE_TO_VERIFY_LEAF_SIGNATURE
Missing intermediate (works in browsers only)
CERT_HAS_EXPIRED
Expired, or wrong client clock
ERR_TLS_CERT_ALTNAME_INVALID
Host name not in SAN
DEPTH_ZERO_SELF_SIGNED_CERT
Self-signed or private CA
Watch out: Never use -k, rejectUnauthorized: false or NODE_TLS_REJECT_UNAUTHORIZED=0: they accept imposters. Trust the right CA. HSTS locks users out if the cert breaks, so start with a short max-age.