---
title: "The Vanishing Thread and Postgresql TCP Connection Parameters"
description: "Instacart traced Puma threads that hung for about 15 minutes, ignoring application and database timeouts, to TCP retransmission storms between the app and an AWS NLB in front of PgBouncer."
url: "https://swe.quest/articles/the-vanishing-thread-and-postgresql-tcp-connection-parameters-955a883b4bb1ed12"
canonical: "https://tech.instacart.com/the-vanishing-thread-and-postgresql-tcp-connection-parameters-93afc0e1208c"
source: "Instacart Tech"
published: "2022-04-15"
difficulty: "medium"
kind: "Case study"
reading_minutes: 16
tags: ["postgres","networking","linux","resilience","debugging"]
---

# The Vanishing Thread and Postgresql TCP Connection Parameters

A post on [Instacart Tech](https://swe.quest/sources/instacart.md), published 2022-04-15, 16 min read, Case study. Original: [https://tech.instacart.com/the-vanishing-thread-and-postgresql-tcp-connection-parameters-93afc0e1208c](https://tech.instacart.com/the-vanishing-thread-and-postgresql-tcp-connection-parameters-93afc0e1208c)

## Summary

Instacart traced Puma threads that hung for about 15 minutes, ignoring application and database timeouts, to TCP retransmission storms between the app and an AWS NLB in front of PgBouncer. Linux's default tcp\_retries2 of 15 with exponential backoff yields roughly 15-minute waits before the OS reports 'Connection timed out'. Setting TCP\_USER\_TIMEOUT and keepalives per connection through libpq cut failure detection to about 13 seconds. The post also serves as a reference for configuring these parameters in connection strings, Rails, PgBouncer, the Postgres server, logical replication subscriptions and FDW servers. It explains how tcp\_user\_timeout overrides syn retries and keepalive probes, and how to infer which timeout fired from the elapsed time.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Networking](https://swe.quest/tags/networking.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)

## Prerequisites

- TCP retransmission and keepalives ([easy posts on Networking](https://swe.quest/tags/networking.md?difficulty=easy))
- PostgreSQL client connections ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- PgBouncer basics

## Keywords

TCP\_USER\_TIMEOUT, PgBouncer, libpq, tcp\_retries2, AWS Network Load Balancer, Ruby on Rails, Puma

## Related posts

- [Pumas, Routers & Keepalives—Oh my!](https://swe.quest/articles/pumas-routers-keepalives-oh-my-4b676798ea4106ef.md): Heroku Engineering · 2024-11-21 · Medium · 17 min read · Debugging, Performance engineering, Ruby, Load balancing, Networking
  Elevated tail latency seen by some Puma apps after enabling Heroku Router 2.0 turned out to be a Puma bug, not a router problem.
- [Production Postgres on Railway: From First Deploy to High Availability](https://swe.quest/articles/production-postgres-on-railway-from-first-deploy-to-high-availability-70a3bcba84354fc9.md): Railway · 2026-10-15 · Medium · 13 min read · PostgreSQL, Replication, Resilience, Cloud platforms
  Railway Postgres can grow from a single private-networked database to a production setup with volume backups, point-in-time recovery, PgBouncer connection pooling and Patroni-based high availability, demonstrated with an orders API that uses idempotency keys so retries stay safe.
- [Incident Report: April 23rd, 2025](https://swe.quest/articles/incident-report-april-23rd-2025-f0e6e4113e1badba.md): Railway · 2025-04-23 · Medium · 4 min read · Incidents & postmortems, Resilience, PostgreSQL, Networking, Caching
  A Google Cloud SQL maintenance window took Railway's networking control plane Postgres read replica offline for about 10 minutes, destabilizing edge, private networking and TCP proxy traffic across all regions, worst in Asia.
- [Using Neon’s Scale to Zero with Long-Running Applications](https://swe.quest/articles/using-neon-s-scale-to-zero-with-long-running-applications-bbe64dd8466d86d8.md): Neon · 2024-01-24 · Medium · 7 min read · PostgreSQL, Serverless, Resilience, JavaScript, Performance engineering
  Neon's scale to zero suspends a Postgres compute after an idle window (only when no WAL senders are active and autovacuum isn't running), which severs connections held by long-running servers.
- [Clouds, caches and connection conundrums](https://swe.quest/articles/clouds-caches-and-connection-conundrums-9abdd4ad0c3450ff.md): incident.io · 2023-09-26 · Medium · 10 min read · Kubernetes, Networking, Incidents & postmortems, Debugging, PostgreSQL
  After migrating to Google Cloud, sporadic Postgres and memcached connection timeouts on GKE turned out to be node-wide, not process-local.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
