Re: client socket TIME_WAIT state after PQfinish

From: Nicolas Barbier <nicolas(dot)barbier(at)gmail(dot)com>
To: Guillaume Du Pasquier <guillaume(dot)dupasquier(at)sensometrix(dot)ch>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: client socket TIME_WAIT state after PQfinish
Date: 2010-09-27 16:22:45
Message-ID: AANLkTimk-BPwJNapy2F0+uAbRVCeySqG+8CwZSBMSc3W@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2010/9/27 Guillaume Du Pasquier <guillaume(dot)dupasquier(at)sensometrix(dot)ch>:

> In both cases, the client socket (pgadmin or my program) remains in
> TIME_WAIT state.
>
> I have used wireshark to sniff the TCP protocol.
>
> We have at the end of a connection:
>
> Client                  Server
>
>    --->    FIN,ACK  --->
>    <---    FIN,ACK  <---
>    --->      ACK    --->
>
> This ends up in a TIME_WAIT state. The TCP protocol should be

According to the Two Generals' Problem [1], one of the sides
necessarily doesn't know whether the other side has received its last
packet. Therefore, TCP lets one of the sides sit in TIME_WAIT status
for as long as any packets could in principle survive on the network
(typically defined as 2 minutes on IP networks IIRC), and potentially
disturb a new connection between the same (dst IP, dst port, src IP,
src port) combination.

[1] <URL:http://en.wikipedia.org/wiki/Two_Generals'_Problem>

> Client                  Server
>
>    --->    FIN,ACK  --->
>    <---      ACK    <---
>    <---    FIN,ACK  <---

AFAIK, this last ACK (in above packet) is not needed: the server can
ACK the client's FIN _while_ it sends its own FIN (by using an
appropriate sequence number, as FIN "uses" one byte in the sequence).

>    --->      ACK    --->
>
> I suppose there is a bug in the postgresql server that do not send an ack to
> the client.

I don't think so.

Nicolas

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2010-09-27 16:25:31 Re: trailing whitespace in psql table output
Previous Message Robert Haas 2010-09-27 15:55:19 Re: A small update for postgresql.conf.sample