pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lfrittelli <leonardo.frittelli@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Connection terminated by the server causes deadlock in jdbc client side connection
Date: Wed, 14 Oct 2015 14:26:31 -0700 (MST)
Message-ID: <1444857991068-5870008.post@n5.nabble.com> (raw)
In-Reply-To: <561A3FC8.6080305@kiwi-fraser.net>
References: <CACh06N3O40kLx9YLH6cT8_DTEdRVt+G+tCBAinrjzhtECHfgUQ@mail.gmail.com>
	<0c59e097a3ec4139b049b89627fb149f@exchange.sh-solutions.de>
	<CADK3HHLsyn=F8V7E8DfbHFFdJJ_EkARqs8FMA8StWTwUB2B1zA@mail.gmail.com>
	<CACh06N0zooU+zSkdSGMHHNsO2hZXszBNZBHnM=nk_DzxSbHUGA@mail.gmail.com>
	<543c7dab3e334742b02d18dcf7b2c49a@exchange.sh-solutions.de>
	<CACh06N3b6h+VPqRPTCj8XuodMLuftMCOp=gHQNhjEMaq3th68g@mail.gmail.com>
	<561A3FC8.6080305@kiwi-fraser.net>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Donald,

These are good points all. Let me provide more context for my scenario on
each item
> First I'd like to say that even though we are dealing with TCP one must
> treat it almost like UDP. TCP
> packets can be consumed by firewalls and proxy servers with no response
> given to the sender. So with
> that in mind to create a robust fault tolerant driver, timeout on all TCP
> communications is a must.

True in the general case, but I don't think it would have affected the
specific scenario under issue. For context on the scenario, note that there
was no firewall or proxy. We were using local connections
(jdbc:postgresql://localhost...)

> 1) So in the first case where an IOException is thrown, the original code
> that is closing the connection
> via "close" cannot have a timeout feature enabled and that will still
> exist in the code with the potential
> to fail...

As the 'graceful' close() method will write on the socket, would it be
possible to put a timeout on write? I am no expert but have not been able to
find out how.


> 2) When an IOException is thrown as the origin of an exception this should
> not be lost and should
> always be attached to the final exception. I don't see this cascaded in
> the updated driver using the
> "abort" code...

At least in some of the cases it appears that the original IO error is
consumed and converted to an error SQL state, and not re-thrown.
In other cases there is actually a message from the server advising of the
termination and this is somehow interpreted by the client, thus no IO
exception in those cases.

Here is a more detailed log capture (including some Hibernate entries) -
again, this is after the fix:

(SqlExceptionHelper.java:145) - SQL Error: 0, SQLState: 40001
(SqlExceptionHelper.java:147) - FATAL: terminating connection due to
conflict with recovery
  Detail: User query might have needed to see row versions that must be
removed.
  Hint: In a moment you should be able to reconnect to the database and
repeat your command.
org.hibernate.exception.LockAcquisitionException: could not extract
ResultSet
        at
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:140)
        at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
        at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
        at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
        at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
        at
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
        at
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
        at org.hibernate.loader.Loader.doQuery(Loader.java:900)
        at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
        at org.hibernate.loader.Loader.doList(Loader.java:2526)
        at org.hibernate.loader.Loader.doList(Loader.java:2512)
        at
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
        at org.hibernate.loader.Loader.list(Loader.java:2337)
        at
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:124)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1662)
        at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
...
Caused by: org.postgresql.util.PSQLException: FATAL: terminating connection
due to conflict with recovery
  Detail: User query might have needed to see row versions that must be
removed.
  Hint: In a moment you should be able to reconnect to the database and
repeat your command.
        at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
        at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:562)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:305)
        ... 46 more

Let me know if there is any additional detail that I could provide.

Regards,

Leonardo




--
View this message in context: http://postgresql.nabble.com/Connection-terminated-by-the-server-causes-deadlock-in-jdbc-client-side...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (18+ messages)  latest in thread

Message-ID: <1444857991068-5870008.post@n5.nabble.com>
Permalink:  ../1444857991068-5870008.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1444857991068-5870008.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: leonardo.frittelli@gmail.com
  Subject: Re: Connection terminated by the server causes deadlock in jdbc client side connection
  In-Reply-To: <1444857991068-5870008.post@n5.nabble.com>
  References: <CACh06N3O40kLx9YLH6cT8_DTEdRVt+G+tCBAinrjzhtECHfgUQ@mail.gmail.com> <0c59e097a3ec4139b049b89627fb149f@exchange.sh-solutions.de> <CADK3HHLsyn=F8V7E8DfbHFFdJJ_EkARqs8FMA8StWTwUB2B1zA@mail.gmail.com> <CACh06N0zooU+zSkdSGMHHNsO2hZXszBNZBHnM=nk_DzxSbHUGA@mail.gmail.com> <543c7dab3e334742b02d18dcf7b2c49a@exchange.sh-solutions.de> <CACh06N3b6h+VPqRPTCj8XuodMLuftMCOp=gHQNhjEMaq3th68g@mail.gmail.com> <561A3FC8.6080305@kiwi-fraser.net> <1444857991068-5870008.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox