Re: BUG #15598: PostgreSQL Error Code is not reported when connection terminated due to idle-in-transaction timeout

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Marcin Barczyński <mba(dot)ogolny(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15598: PostgreSQL Error Code is not reported when connection terminated due to idle-in-transaction timeout
Date: 2019-01-21 12:08:08
Message-ID: 87k1iy44fd.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "Marcin" == Marcin Barczyński <mba(dot)ogolny(at)gmail(dot)com> writes:

Marcin> Unfortunately, it's not the problem of verbosity.

Marcin> The error code is printed properly in case of duplicate key
Marcin> violation. It seems that something is wrong with
Marcin> idle-in-transaction timeout on Windows:

I think this is domain-dependent or platform-dependent behavior of the
result of sending data on an already-closed connection.

On Ubuntu, were you using psql -h localhost, or psql with no host
parameter (which uses local-domain sockets by default, whereas with -h
localhost it uses TCP)?

When the server forces a connection to be closed like this, it writes
the ErrorResponse packet, and then closes the connection and ends the
backend process. Since psql does not expect data at that point, the
packet will (at best) remain buffered waiting to be read.

But when you do the next query, I am fairly sure that libpq will _write_
the new query to the connection before checking for any input. If the
connection is via TCP to localhost, that write may well result in an
immediate reset of the connection (since no process is available to read
from the other end), which may cause the buffered data to be discarded
before libpq can read it, so you never see it.

This isn't something we can reasonably fix, it's inherent to how the
network protocol implementations work. Only a client program that's
prepared to check for incoming data on an idle connection (which psql
does not) has any chance of reliably getting the error packet from a
forcibly closed connection (though clients that are not local to the
database host should _usually_ get it even if they do not check).

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2019-01-21 15:30:26 BUG #15600: ts_stat's nentry maxes out at 255
Previous Message Marcin Barczyński 2019-01-21 08:55:22 Re: BUG #15598: PostgreSQL Error Code is not reported when connection terminated due to idle-in-transaction timeout