Thread: SocketException: Connection reset

SocketException: Connection reset

From
""
Date:
Hi,

my problem is simple, but frustrating for me:

JDBC driver: postgresql-8.3-604.jdbc4.jar
Server: PostgreSQL 8.3.5, compiled by Visual C++
build 1400

Code (found cause, so very simplified):

public class Main {
    public static void main(String[] args) throws
Exception
    {
        java.util.Properties props = new
java.util.Properties();
        props.setProperty(\"user\", \"postgres\");
        props.setProperty(\"password\",
\"secretpassword\");
        for (int i = 0; i < 100; i++)
        {
            System.out.println(\"attempt number \"
+ i);
            java.sql.Connection con =
java.sql.DriverManager.getConnection(

\"jdbc:postgresql://localhost:5432/my\", propsDB);
            con.close();
        }
    }
}

Code produces (... for abbreviation):

run:
attempt number 0
attempt number 1
...
attempt number 68
attempt number 69
Exception in thread \"main\"
org.postgresql.util.PSQLException: The connection
attempt failed.
        at
org.postgresql.Driver$ConnectThread.getResult(Driver.java:341)
        at
org.postgresql.Driver.connect(Driver.java:264)
        at
java.sql.DriverManager.getConnection(DriverManager.java:582)
        at
java.sql.DriverManager.getConnection(DriverManager.java:154)
        at sometests.Main.main(Main.java:85)
Caused by: java.net.SocketException: Connection
reset
        at
java.net.SocketInputStream.read(SocketInputStream.java:168)
        at
org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:135)
        at
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:104)
        at
org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)
        at
org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259)
        at
org.postgresql.core.v2.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:207)
        at
org.postgresql.core.v2.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
        at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
        at
org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
        at
org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
        at
org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:29)
        at
org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
        at
org.postgresql.Driver.makeConnection(Driver.java:386)
        at
org.postgresql.Driver.access$100(Driver.java:47)
        at
org.postgresql.Driver$ConnectThread.run(Driver.java:301)
        at java.lang.Thread.run(Thread.java:619)
Java Result: 1


Sometimes it happens after just 8 attempts,
sometimes after 80, sometimes after 780 attempts.
I googled for some
time, no solution found.

Thank you for any suggestions.













z


--- === www.INFOWEB.cz === ---




Re: SocketException: Connection reset

From
Craig Ringer
Date:
zxcv@infoweb.cz wrote:

> \"jdbc:postgresql://localhost:5432/my\", propsDB);

> attempt number 69
> Exception in thread \"main\"
> org.postgresql.util.PSQLException: The connection
> attempt failed.

> Caused by: java.net.SocketException: Connection
> reset
>         at
> java.net.SocketInputStream.read(SocketInputStream.java:168)

> org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259)
>         at
> org.postgresql.core.v2.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:207)

Does anything appear in the PostgreSQL server logs? Try turning up
logging verbosity and see if you get anything informative when logging
is set to debug level.

Do you have a virus scanner or firewall product installed on the
machine? If so, does the problem go away if you UNINSTALL (not merely
disable) the product then run "netsh interface ip reset c:\resetlog.txt"
in cmd.exe ? I repeat, in many cases disabling firewall/AV products is
NOT sufficient, they must often be UNINSTALLED to get rid of the filter
drivers that cause problems.

--
Craig Ringer