Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id DDA429FB924 for ; Thu, 19 Apr 2007 11:05:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 81836-07 for ; Thu, 19 Apr 2007 11:05:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id 91BB19FB4B4 for ; Thu, 19 Apr 2007 11:05:50 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id k3so542995ugf for ; Thu, 19 Apr 2007 07:05:48 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:subject:from:to:content-type:date:message-id:mime-version:x-mailer; b=XpppxhPDL3faA03d3U7Y9ACY9NNOSOGb/K/BGcpSFPxIfVbIrDgWZqXipll+Qaww/6JThdMUXfFmtNAMkhOB4SCtSo3KsWWmgyCjI+4UTeHWLgy3ZIv1vcs/2P9SOT3ZjEzJTM5CMYaDQyY8PmQvq8Py1H45tL+ghpYKj/Uw4tk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:subject:from:to:content-type:date:message-id:mime-version:x-mailer; b=NrPyj4R+GzGN0spZvxUslmqWWLThVK5ZYy0aaGHsn/mnv6CxxS9Ocy7XMc3vLgw0nRX1Tc5hNN37nZCwCeHcjf/WXgWkxziIkvCUuvqa3qvAM9Baw/kpdPZL1y230bBUHDh5sxvvOOPs1Ap1AuSGCCZE4B9tKk0Jv7Tk/xTKhuE= Received: by 10.82.120.14 with SMTP id s14mr2881843buc.1176991548411; Thu, 19 Apr 2007 07:05:48 -0700 (PDT) Received: from ?192.168.1.13? ( [90.38.175.17]) by mx.google.com with ESMTP id p32sm3105703ugc.2007.04.19.07.05.47; Thu, 19 Apr 2007 07:05:47 -0700 (PDT) Subject: robust handling of initial connection with net interfaces down From: Adrian Custer To: pgsql-jdbc@postgresql.org Content-Type: multipart/mixed; boundary="=-6ka1Ly3PaIrWGA5dOn2x" Date: Thu, 19 Apr 2007 16:05:45 +0200 Message-Id: <1176991545.18583.4.camel@blackpad> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/63 X-Sequence-Number: 16912 --=-6ka1Ly3PaIrWGA5dOn2x Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-6ka1Ly3PaIrWGA5dOn2x Content-Disposition: attachment; filename=JDBCTest.java Content-Type: text/x-java; name=JDBCTest.java; charset=UTF-8 Content-Transfer-Encoding: 7bit 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!"); } } --=-6ka1Ly3PaIrWGA5dOn2x--