Skip to content

Document limits on socketTimeout and connectTimeout property #2671

@alex-ooiwc

Description

@alex-ooiwc

Describe the issue
Documentation located here states that connectTimeout and socketTimeout are int, but values 2147484 or above will cause an integer overflow due to multiplication being applied here and here.

To Reproduce
Set socketTimeout or connectTimeout property to 2147484 or above.

Expected behaviour
Documentation should clearly state that while it is an int, the upper limit of the property is 2147483, otherwise integer overflow will occur.

Logs

org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
	at org.postgresql.Driver.connect(Driver.java:314)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:191)
	at com.example.postgresjdbc.Main.main(Main.java:18)
Caused by: java.lang.IllegalArgumentException: connect: timeout can't be negative

Code to replicate:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class Main {
    public static void main(String []args) throws Exception {
        String url = "jdbc:postgresql://127.0.0.1:5432/test";

        Properties props = new Properties();
        props.setProperty("user", "test");
        props.setProperty("password", "test");
        props.setProperty("socketTimeout", "2147484");
        props.setProperty("connectTimeout", "2147484");
        try ( Connection conn = DriverManager.getConnection(url, props) ){
            try ( Statement statement = conn.createStatement() ) {
                try (ResultSet rs = statement.executeQuery( "select 1") ){
                    if (rs.next())
                        System.out.println( "Get String: " + rs.getString(1));
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions