Concepts and theorems · Intermediate

Connection state: distinguish establishment, half-close and termination

Track TCP’s two directions and distinguish protocol state from application readiness or remote health.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Connection state describes a protocol stage
  2. Trace a half-close
  3. Closing states have distinct purposes
  4. Application deadlines remain necessary
  5. Ask Logeia about this articleCheck your understanding

Connection state describes a protocol stage

A TCP connection has stages such as establishment, data transfer and closing, not merely a connected Boolean. Each endpoint updates its state using its own events and received control information, so the endpoints need not occupy identically named states at the same instant. An application’s “connected” indicator does not prove that the peer is healthy or that the next request will succeed. Protocol state supports the transport contract; it is not a direct description of business processing or durable completion. Interpret it alongside application-level evidence and deadlines rather than as a complete health assessment.

Trace a half-close

A client can finish sending its request, half-close its sending direction and continue receiving the server’s response. TCP supports two directions of byte flow, so ending one direction does not necessarily make the other direction unusable immediately. The server observing the client’s FIN and the client receiving the server’s final response are different events. Draw which endpoint sent a FIN and where outstanding data remains. That makes a protocol trace more informative than saying only that “the connection closed,” especially when diagnosing a server that is still allowed to send its response.

Closing states have distinct purposes

Normal closing includes states that help handle delayed traffic and closing acknowledgements. Seeing TIME-WAIT alone does not prove that an application leaked a connection. An abort using RST is also different from the normal FIN exchange. The errors reported by socket operations depend on state, unread data and timing. Do not try to eliminate a state name merely because it appears frequently. Correlate the path into that state with the application’s operations and observed control traffic, and distinguish expected protocol cleanup from a resource that the application has failed to release.

Application deadlines remain necessary

A broken path or stopped peer does not always deliver an immediate, explicit closing notification. An idle connection may reveal a failure only much later. Keepalive and timeout mechanisms can aid detection, but they do not establish that the remote application completed a request. Define request deadlines, duplicate-handling rules for retries and conditions for reusing connections. Tools such as ss and packet traces can help connect state distributions to application waits. Reading counts and state names together with request outcomes is more useful than assuming that an established connection guarantees a responsive service.

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Understand the systems behind the web · STEP 10

Choose a learning path