pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedInvalid PSQLState used in connection classes
4+ messages / 3 participants
[nested] [flat]
* Invalid PSQLState used in connection classes
@ 2011-03-08 16:03 Donald Fraser <postgres@kiwi-fraser.net>
2011-03-08 16:48 ` Re: Invalid PSQLState used in connection classes Kevin Grittner <Kevin.Grittner@wicourts.gov>
0 siblings, 1 reply; 4+ messages in thread
From: Donald Fraser @ 2011-03-08 16:03 UTC (permalink / raw)
To: pgsql-jdbc
I have noted in the Java code;
File: /org/postgresql/core/v3/ConnectionFactoryImpl.java
Class: ConnectionFactoryImpl
<code snipit>
catch (ConnectException cex)
{
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
throw new PSQLException (GT.tr("Connection refused. Check that the hostname
and port are correct and that the postmaster is accepting TCP/IP
connections."), PSQLState.CONNECTION_REJECTED, cex);
}
</code snipit>
that the use of PSQLState.CONNECTION_REJECTED (08004) is incorrect.
According to the documentation, a CONNECTION_REJECTED error means that the
PostgreSQL server has rejected the connection.
However if I have a broken network between my client and the server, such
that there is no route to the server, I can get a ConnectException and I
have not established, in any way, a connection to the PostgreSQL server.
Why am I complaining about it?
For automation purposes where the client automatically reconnects when a
broken connection is detected we do not want to keep retrying when we get a
CONNECTION_REJECTED from the PostgreSQL server. Because this is meant to
indicate that there is something wrong with our credentials, permissions or
other settings on the server (e.g. pg_hba.conf).
Remote networks over the Internet can often go down and we would like our
automated systems to re-establish such connections, but we can't if the
driver reports CONNECTION_REJECTED for conditions that are not true.
Regards
Donald Fraser
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Invalid PSQLState used in connection classes
2011-03-08 16:03 Invalid PSQLState used in connection classes Donald Fraser <postgres@kiwi-fraser.net>
@ 2011-03-08 16:48 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-03-19 23:47 ` Re: Invalid PSQLState used in connection classes Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Grittner @ 2011-03-08 16:48 UTC (permalink / raw)
To: Donald Fraser <postgres@kiwi-fraser.net>; pgsql-jdbc
"Donald Fraser" <postgres@kiwi-fraser.net> wrote:
> However if I have a broken network between my client and the
> server, such that there is no route to the server, I can get a
> ConnectException and I have not established, in any way, a
> connection to the PostgreSQL server.
08001 - SQLCLIENT UNABLE TO ESTABLISH SQLCONNECTION
Sounds better for that sort of failure.
-Kevin
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Invalid PSQLState used in connection classes
2011-03-08 16:03 Invalid PSQLState used in connection classes Donald Fraser <postgres@kiwi-fraser.net>
2011-03-08 16:48 ` Re: Invalid PSQLState used in connection classes Kevin Grittner <Kevin.Grittner@wicourts.gov>
@ 2011-03-19 23:47 ` Kris Jurka <books@ejurka.com>
2011-03-31 03:07 ` Re: Invalid PSQLState used in connection classes Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 4+ messages in thread
From: Kris Jurka @ 2011-03-19 23:47 UTC (permalink / raw)
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>; +Cc: Donald Fraser <postgres@kiwi-fraser.net>; pgsql-jdbc
On Tue, 8 Mar 2011, Kevin Grittner wrote:
> "Donald Fraser" <postgres@kiwi-fraser.net> wrote:
>
>> However if I have a broken network between my client and the
>> server, such that there is no route to the server, I can get a
>> ConnectException and I have not established, in any way, a
>> connection to the PostgreSQL server.
>
> 08001 - SQLCLIENT UNABLE TO ESTABLISH SQLCONNECTION
>
> Sounds better for that sort of failure.
>
Sounds reasonable to me. Looking at the error codes used during startup,
I think we should also make some other changes at the same time.
CONNECTION_UNABLE_TO_CONNECT -> PROTOCOL_VIOLATION
CONNECTION_FAILURE -> PROTOCOL_VIOLATION
when the driver receives an unknown message.
CONNECTION_FAILURE -> CONNECTION_REJECTED
when the server doesn't support SSL, but we need a SSL connection. I
think CONNECTION_FAILURE should only be used when something has gone wrong
after a connection has been established.
Patch attached.
Kris Jurka
Attachments:
connection-sqlstates.patch (text/plain, 12.7K) download
Index: org/postgresql/core/v2/ConnectionFactoryImpl.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/core/v2/ConnectionFactoryImpl.java,v
retrieving revision 1.20
diff -c -r1.20 ConnectionFactoryImpl.java
*** org/postgresql/core/v2/ConnectionFactoryImpl.java 25 Dec 2010 07:07:44 -0000 1.20
--- org/postgresql/core/v2/ConnectionFactoryImpl.java 19 Mar 2011 23:34:44 -0000
***************
*** 101,107 ****
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
! throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_REJECTED, cex);
}
catch (IOException ioe)
{
--- 101,107 ----
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
! throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_UNABLE_TO_CONNECT, cex);
}
catch (IOException ioe)
{
***************
*** 155,161 ****
// Server doesn't even know about the SSL handshake protocol
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
// We have to reconnect to continue.
pgStream.close();
--- 155,161 ----
// Server doesn't even know about the SSL handshake protocol
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
// We have to reconnect to continue.
pgStream.close();
***************
*** 167,173 ****
// Server does not support ssl
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
return pgStream;
--- 167,173 ----
// Server does not support ssl
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
return pgStream;
***************
*** 180,186 ****
return pgStream;
default:
! throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.CONNECTION_FAILURE);
}
}
--- 180,186 ----
return pgStream;
default:
! throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.PROTOCOL_VIOLATION);
}
}
***************
*** 319,325 ****
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
}
}
--- 319,325 ----
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
}
}
}
***************
*** 357,363 ****
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
}
}
--- 357,363 ----
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
}
}
}
Index: org/postgresql/core/v3/ConnectionFactoryImpl.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v
retrieving revision 1.23
diff -c -r1.23 ConnectionFactoryImpl.java
*** org/postgresql/core/v3/ConnectionFactoryImpl.java 25 Dec 2010 07:07:44 -0000 1.23
--- org/postgresql/core/v3/ConnectionFactoryImpl.java 19 Mar 2011 23:34:44 -0000
***************
*** 135,141 ****
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
! throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_REJECTED, cex);
}
catch (IOException ioe)
{
--- 135,141 ----
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
! throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_UNABLE_TO_CONNECT, cex);
}
catch (IOException ioe)
{
***************
*** 187,193 ****
// Server doesn't even know about the SSL handshake protocol
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
// We have to reconnect to continue.
pgStream.close();
--- 187,193 ----
// Server doesn't even know about the SSL handshake protocol
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
// We have to reconnect to continue.
pgStream.close();
***************
*** 199,205 ****
// Server does not support ssl
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
return pgStream;
--- 199,205 ----
// Server does not support ssl
if (requireSSL)
! throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
return pgStream;
***************
*** 212,218 ****
return pgStream;
default:
! throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.CONNECTION_FAILURE);
}
}
--- 212,218 ----
return pgStream;
default:
! throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.PROTOCOL_VIOLATION);
}
}
***************
*** 406,412 ****
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
}
}
--- 406,412 ----
break;
default:
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
}
}
}
***************
*** 449,455 ****
// BackendKeyData
int l_msgLen = pgStream.ReceiveInteger4();
if (l_msgLen != 12)
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
int pid = pgStream.ReceiveInteger4();
int ckey = pgStream.ReceiveInteger4();
--- 449,455 ----
// BackendKeyData
int l_msgLen = pgStream.ReceiveInteger4();
if (l_msgLen != 12)
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
int pid = pgStream.ReceiveInteger4();
int ckey = pgStream.ReceiveInteger4();
***************
*** 495,501 ****
else if (name.equals("client_encoding"))
{
if (!value.equals("UNICODE"))
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
pgStream.setEncoding(Encoding.getDatabaseEncoding("UNICODE"));
}
else if (name.equals("standard_conforming_strings"))
--- 495,501 ----
else if (name.equals("client_encoding"))
{
if (!value.equals("UNICODE"))
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
pgStream.setEncoding(Encoding.getDatabaseEncoding("UNICODE"));
}
else if (name.equals("standard_conforming_strings"))
***************
*** 505,511 ****
else if (value.equals("off"))
protoConnection.setStandardConformingStrings(false);
else
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
break;
--- 505,511 ----
else if (value.equals("off"))
protoConnection.setStandardConformingStrings(false);
else
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
}
break;
***************
*** 513,519 ****
default:
if (logger.logDebug())
logger.debug("invalid message type=" + (char)beresp);
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
}
}
--- 513,519 ----
default:
if (logger.logDebug())
logger.debug("invalid message type=" + (char)beresp);
! throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
}
}
}
Index: org/postgresql/util/PSQLState.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/util/PSQLState.java,v
retrieving revision 1.13
diff -c -r1.13 PSQLState.java
*** org/postgresql/util/PSQLState.java 8 Jan 2008 06:56:31 -0000 1.13
--- org/postgresql/util/PSQLState.java 19 Mar 2011 23:34:44 -0000
***************
*** 37,48 ****
--- 37,70 ----
public final static PSQLState INVALID_PARAMETER_TYPE = new PSQLState("07006");
+ /**
+ * We could establish a connection with the server for unknown reasons.
+ * Could be a network problem.
+ */
public final static PSQLState CONNECTION_UNABLE_TO_CONNECT = new PSQLState("08001");
+
public final static PSQLState CONNECTION_DOES_NOT_EXIST = new PSQLState("08003");
+
+ /**
+ * The server rejected our connection attempt. Usually an authentication
+ * failure, but could be a configuration error like asking for a SSL
+ * connection with a server that wasn't built with SSL support.
+ */
public final static PSQLState CONNECTION_REJECTED = new PSQLState("08004");
+
+ /**
+ * After a connection has been established, it went bad.
+ */
public final static PSQLState CONNECTION_FAILURE = new PSQLState("08006");
public final static PSQLState CONNECTION_FAILURE_DURING_TRANSACTION = new PSQLState("08007");
+
+ /**
+ * The server sent us a response the driver was not prepared for and
+ * is either bizarre datastream corruption, a driver bug, or
+ * a protocol violation on the server's part.
+ */
public final static PSQLState PROTOCOL_VIOLATION = new PSQLState("08P01");
+
public final static PSQLState COMMUNICATION_ERROR = new PSQLState("08S01");
public final static PSQLState NOT_IMPLEMENTED = new PSQLState("0A000");
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Invalid PSQLState used in connection classes
2011-03-08 16:03 Invalid PSQLState used in connection classes Donald Fraser <postgres@kiwi-fraser.net>
2011-03-08 16:48 ` Re: Invalid PSQLState used in connection classes Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-03-19 23:47 ` Re: Invalid PSQLState used in connection classes Kris Jurka <books@ejurka.com>
@ 2011-03-31 03:07 ` Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 4+ messages in thread
From: Kris Jurka @ 2011-03-31 03:07 UTC (permalink / raw)
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>; +Cc: Donald Fraser <postgres@kiwi-fraser.net>; pgsql-jdbc
On Sat, 19 Mar 2011, Kris Jurka wrote:
>
> On Tue, 8 Mar 2011, Kevin Grittner wrote:
>
>> "Donald Fraser" <postgres@kiwi-fraser.net> wrote:
>>
>>> However if I have a broken network between my client and the
>>> server, such that there is no route to the server, I can get a
>>> ConnectException and I have not established, in any way, a
>>> connection to the PostgreSQL server.
>>
>> 08001 - SQLCLIENT UNABLE TO ESTABLISH SQLCONNECTION
>>
>> Sounds better for that sort of failure.
>>
>
> Sounds reasonable to me. Looking at the error codes used during startup, I
> think we should also make some other changes at the same time.
>
> CONNECTION_UNABLE_TO_CONNECT -> PROTOCOL_VIOLATION
> CONNECTION_FAILURE -> PROTOCOL_VIOLATION
> when the driver receives an unknown message.
>
> CONNECTION_FAILURE -> CONNECTION_REJECTED
> when the server doesn't support SSL, but we need a SSL connection. I think
> CONNECTION_FAILURE should only be used when something has gone wrong after a
> connection has been established.
>
> Patch attached.
>
Applied to CVS for 8.2+.
Kris Jurka
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2011-03-31 03:07 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 16:03 Invalid PSQLState used in connection classes Donald Fraser <postgres@kiwi-fraser.net>
2011-03-08 16:48 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-03-19 23:47 ` Kris Jurka <books@ejurka.com>
2011-03-31 03:07 ` Kris Jurka <books@ejurka.com>
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