# When TCP sockets refuse to die

DevFeed: [When TCP sockets refuse to die](<https://devfeed.tech/articles/when-tcp-sockets-refuse-to-die-38987.md>)

Original publisher: [Read original article](<https://idea.popcount.org/2019-09-20-when-tcp-sockets-refuse-to-die>)

Author: Marek

Published: 2019-09-19T22:00:00Z

Content type: tutorial

Language: en

Sources: [Marek Majkowski](<https://devfeed.tech/sources/marek-majkowski.md>)

Topics: [Linux](<https://devfeed.tech/topics/linux.md>), [Kernel](<https://devfeed.tech/topics/kernel.md>), [Server](<https://devfeed.tech/topics/server.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [blog](<https://devfeed.tech/tags/blog.md>), [bug](<https://devfeed.tech/tags/bug.md>), [cloudflare](<https://devfeed.tech/tags/cloudflare.md>), [commands](<https://devfeed.tech/tags/commands.md>), [kernel](<https://devfeed.tech/tags/kernel.md>), [retries](<https://devfeed.tech/tags/retries.md>), [scripts](<https://devfeed.tech/tags/scripts.md>), [tcp](<https://devfeed.tech/tags/tcp.md>), [timeout](<https://devfeed.tech/tags/timeout.md>)

## AI overview

A technical tutorial explains when Linux TCP sockets time out and how TCP keepalives and the TCP_USER_TIMEOUT socket option interact. It discusses connection establishment, SYN retries, kernel behavior, and a possible bug observed on Linux kernel 5.2.

## Source excerpt

When TCP sockets refuse to die This article was first published on Cloudflare blog: While working on our Spectrum server, we noticed something weird: the TCP sockets which we thought should have been closed were lingering around. We realized we don't really understand when TCP sockets are supposed to time out! In our code, we wanted to make sure we don't hold connections to dead hosts. In our early code we naively thought enabling TCP keepalives would be enough... but it isn't.