pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
robust handling of initial connection with net interfaces down
3+ messages / 2 participants
[nested] [flat]

* robust handling of initial connection with net interfaces down
@ 2007-04-19 14:05  Adrian Custer <acuster@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Adrian Custer @ 2007-04-19 14:05 UTC (permalink / raw)
  To: pgsql-jdbc

hey all,

i'm trying to make our app's connection to postgresql robust. In
testing, I've noticed that if the network interfaces don't exist, the
java instance locks up.

0.setup the server e.g. localhost:5432, user:auser, password:hello

1. Take down your network e.g. ifdown lo

2. run a simple connect to postgresql jdbc such as the file attached

==> the file hangs indefinitely.

Does anyone have a suggestion for preventing this? 

Thanks,
adrian

Attachments:

JDBCTest.java (text/x-java, 1.6K) download package com.eofabrik.testing.jdbc; import java.sql.*; public class JDBCTest { public static void main(String[] args) { System.out.println("Start Test...\n"); //requires postgresql-VERSION.jar on classpath try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String jdbcURL = "jdbc:postgresql"; String host = "localhost"; String port = "5432"; String login = "acuster"; String pass = "hello"; String db = "coredb"; String jdbcPgsqlURL = jdbcURL + "://" + host + ":" + port + "/" + db + ":anythinggoes?"; Connection dbConnection = null; ResultSet rs = null; DriverManager.setLoginTimeout(1); //what does this actually do? We still hang on no net. try{ dbConnection = DriverManager.getConnection(jdbcPgsqlURL, login, pass); } catch( SQLException ex ){ //System.out.println( "Couldn't get connection!" ); System.out.println(ex.getMessage()); } if (null != dbConnection){ try { rs = dbConnection.getMetaData().getCatalogs(); System.out.println("Catalogs are:"); while (rs.next()){ System.out.println(" " + rs.getString(1) ); } System.out.println(); rs = dbConnection.getMetaData().getSchemas(); System.out.println("Schema are:"); while (rs.next()){ System.out.println(" " + rs.getString(1) ); } System.out.println(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("\n...End Test. Have a nice day!"); } }
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: robust handling of initial connection with net interfaces down
@ 2007-04-19 16:15  Kris Jurka <books@ejurka.com>
  parent: Adrian Custer <acuster@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2007-04-19 16:15 UTC (permalink / raw)
  To: Adrian Custer <acuster@gmail.com>; +Cc: pgsql-jdbc



On Thu, 19 Apr 2007, Adrian Custer wrote:

> i'm trying to make our app's connection to postgresql robust. In
> testing, I've noticed that if the network interfaces don't exist, the
> java instance locks up.
>
> 0.setup the server e.g. localhost:5432, user:auser, password:hello
>
> 1. Take down your network e.g. ifdown lo
>
> 2. run a simple connect to postgresql jdbc such as the file attached
>
> ==> the file hangs indefinitely.
>
> Does anyone have a suggestion for preventing this?
>

The PG driver does not respect DriverManager.getLoginTimeout, although I'm 
not sure why.  You can instead add the URL parameter ?loginTimeout=5 or 
similar to get a timeout on failure to setup a connection.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: robust handling of initial connection with net interfaces down
@ 2007-07-16 05:17  Kris Jurka <books@ejurka.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Kris Jurka @ 2007-07-16 05:17 UTC (permalink / raw)
  To: Adrian Custer <acuster@gmail.com>; +Cc: pgsql-jdbc



On Thu, 19 Apr 2007, Kris Jurka wrote:

> On Thu, 19 Apr 2007, Adrian Custer wrote:
>
>> i'm trying to make our app's connection to postgresql robust. In
>> testing, I've noticed that if the network interfaces don't exist, the
>> java instance locks up.
>> 
>> 0.setup the server e.g. localhost:5432, user:auser, password:hello
>> 
>> 1. Take down your network e.g. ifdown lo
>> 
>> 2. run a simple connect to postgresql jdbc such as the file attached
>> 
>> ==> the file hangs indefinitely.
>> 
>> Does anyone have a suggestion for preventing this?
>> 
>
> The PG driver does not respect DriverManager.getLoginTimeout, although I'm 
> not sure why.  You can instead add the URL parameter ?loginTimeout=5 or 
> similar to get a timeout on failure to setup a connection.
>

I've committed a change to CVS to make the driver check the 
DriverManager's loginTimeout setting if none has been specified explicitly 
via the URL.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-07-16 05:17 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-19 14:05 robust handling of initial connection with net interfaces down Adrian Custer <acuster@gmail.com>
2007-04-19 16:15 ` Kris Jurka <books@ejurka.com>
2007-07-16 05:17   ` 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