brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ss -o shows the keepalive and retransmit timers of each Linux TCP connection

Linux
~/tips/tip-linux-ss-o-tcp-timers

ss -tno state established

See whether a connection is waiting on keepalive, retransmits or a closing timer.

A connection that hangs instead of failing is often stuck on a timer. The -o option makes ss print those timers next to every socket.

ss -tno state established

Each line now ends with something like timer:(keepalive,58sec,0). The first field is the kind of timer, the second is how long until it fires, and the last number counts how many times it already fired.

The kinds tell you a lot. keepalive means the program asked for TCP keepalives, so a dead peer will be noticed sooner or later. on is the retransmit timer: data was sent and the other side has not acknowledged it yet. If that counter keeps climbing, packets are getting lost somewhere along the path. timewait belongs to connections that are already closed and only waiting out their last minute.

A connection with no timer at all is idle and has no keepalive. If the far end disappears without a goodbye, the kernel will not notice until the program writes something, so an idle database connection behind a firewall can look healthy for hours.

I like it with a port filter, like ss -tno state established '( dport = :5432 )', so you only look at one service. The timers move fast, so run it a few times before you draw conclusions from a single line.

Further reading: ss(8) manual page, tcp(7) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link