{"canonical_url":"https://engineer.company/glossary/connection-timeout/","content_markdown":"# Connection timeout\n\n## What it is\n\nA connection timeout limits how long an operation may spend establishing a\nusable connection. A client can need to resolve an address, open a transport\nconnection and complete a security handshake before it can send an application\nrequest. Different tools assign those steps to different limits. Check the\nimplementation's definition before interpreting a setting or comparing results.\n\nThe time for establishing a connection is only one part of an operation's\nbudget. There can also be time spent waiting for a free connection in a pool,\nsending the request, waiting for the first response bytes and reading the\nremaining response. A service can define limits for those steps and a deadline\nfor the entire operation. A timeout record becomes more useful when it\nidentifies the phase that ran out of time.\n\nSome clients work with persistent connections. A later request can reuse a live\nconnection and skip some or all of its initial setup. As a result, a connection\ntimeout observed during startup can describe a different path from the time\nspent serving ordinary traffic. A representative check should cover both new\nconnections and reuse.\n\n## Why it matters\n\nAn unbounded wait can tie up resources and make users wait long after the\nproduct could give them a useful answer. A timeout puts a limit on an operation\nduring a defined phase. A very small value can also reject viable connections\nduring typical network variance. Choose the limit from the operation's total\nbudget, the cost of a failed attempt and what users can realistically do if it\nfails.\n\nThe position of the timeout affects what can safely be repeated. When contact\nwas never established, a caller has different evidence from a caller that sent\nthe complete request and lost the reply. A later retry could duplicate a durable\neffect. Track when the request was sent and use an operation identity where the\noutcome can be uncertain. Schedule repetitions within the original deadline,\nleaving time for the caller to see a meaningful result.\n\nTimed observations help find the bottleneck. Failed address resolution, a\nstalled connection and an upstream that accepts a connection but takes a long\ntime to reply are different problems. Before changing a timeout, record which\nphase failed and what happened to other requests using the same route. A longer\nvalue can consume more connection slots while leaving the actual cause\nuntouched.\n\n## What it looks like in practice\n\nConsider an application calling an external notification service. Start with a\nusable budget for the full operation and allocate a part for new connections.\nMeasure normal connection setup from the real deployment environment. Exercise a\nrequest using a fresh connection, a reused connection and a deliberately slow\nupstream reply. Confirm which limits apply and which error the caller receives.\nWhen a request fails, record whether any bytes were sent before the deadline.\n\nInclude the retry policy in the one experiment. If the first attempt consumes\nmost of the available time, the next attempt has only the remaining budget. Use\na bounded number of attempts and measure the pooled connections and active\nrequests while an upstream is slow. See whether the team can tell when a\nconnection is unavailable and when an upstream application is taking longer than\nthe product can wait.\n\nEngineer's\n[email delivery case study](/portfolio/built-email-with-failover-and-delivery-logging/)\nrecords a timeout on the send path, along with provider failover and evidence\nabout message delivery. Those features give a concrete context for classifying\nthe failure. The notification example here makes connection setup and later\nresponse time separate measurements. This distinction helps an operator decide\nwhether a failure concerned contact with a provider or the result of a request\nit already received.\n\nPlan an exercise for a service that has several possible addresses or endpoints.\nA client may divide the budget among attempts or try them according to its own\nconnection strategy. Record which endpoint was tried and the deadline applied.\nThese details make the result explainable when a service is reachable by one\npath while another path remains slow.\n\n## Where it goes wrong\n\nA project can copy a timeout value from another tool and assume the same phases\nare covered. Read how the input is defined. For example, a client may include\nDNS and negotiation in its period for establishing a connection, while a reverse\nproxy describes an upstream-specific connection step. Test the real\nimplementation and document the boundary with the configured value.\n\nPooling can also obscure a problem. A healthy warm connection hides a slow\nestablishment path until the pool turns over. Test a fresh process, a normal\nreused connection and recovery after an idle period. Measure what happens when\nmany clients need new connections at the same time. A client can spend more time\nwaiting for its pool than it spends making a single connection.\n\nA useful diagnostic set includes a timestamp for the start of a request, the\nstart of connection acquisition and the first observation after connection. Add\na separate field for receipt of the first response byte. When a recorded\ntimestamp is unavailable, preserve the reason or phase that could be observed.\nWith those readings, a release test can tell whether a new client began waiting\nearlier or stayed longer in one particular step.\n\nFinally, name the effect a deadline has on the next action. The service might\nreturn a clear error, queue the request for a later attempt or report an\nuncertain outcome. The useful timeout is one whose trigger, observed phase and\nrecovery behaviour can all be reproduced. Include the trigger, phase and\nexpected recovery behaviour in the operational record so responders can match it\nto a real failure.\n\n## Further reading\n\n- [libcurl CURLOPT_CONNECTTIMEOUT](https://curl.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html).\n  Describes the time used for the connection phase in libcurl.\n- [nginx upstream connection timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout).\n  Documents connection setup for a proxied request.\n- [Go net.Dialer](https://pkg.go.dev/net#Dialer). Documents deadline and timeout\n  behaviour for network dialing.\n\n\u003chttps://engineer.company/glossary/connection-timeout/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Separate connection setup from later response time and diagnose where time is spent before adjusting deadlines.","formats":{"gemtext":"https://engineer.company/glossary/connection-timeout/index.gmi","gopher":"https://engineer.company/glossary/connection-timeout/gophermap","html":"https://engineer.company/glossary/connection-timeout/","json":"https://engineer.company/glossary/connection-timeout/index.json","markdown":"https://engineer.company/glossary/connection-timeout/index.md","pdf":"https://engineer.company/glossary/connection-timeout/index.pdf"},"kind":"page","language":"en","title":"What is a connection timeout?","url":"https://engineer.company/glossary/connection-timeout/","version":1}