Skip to content

File descriptors leakage in PGStream #2684

@D01B

Description

@D01B

Describe the issue
Strange behaviour in PGStream class, sometimes it can’t close descriptors that it uses.
In case of opening connection to unknown host (like not-exists-exists.com), method [private Socket createSocket(int timeout) throws IOException] at line 241, ‘socket.connect(…)’ generates java.net.UnknownHostException: not-exists-exists.com
Just after that PGStream is loosing reference to socket and can’t close all socket resources.
Unclosed resources trigger JVM to generate java.net.SocketException: Too many open files

Driver Version?
42.5.1

Java Version?
17.0.5

OS Version?
MacOS 12.5.1
PostgreSQL Version?
any
To Reproduce

java.util.Properties info = new java.util.Properties();
        info.put("user", "user");
        info.put("password", "pass");

        for (int i = 0; i < 10000; i++) {
            try {
                Connection connection = DriverManager.getConnection("jdbc:postgresql://not-exists-exists.com:5432/db", info);
                connection.close();
            }
            catch (Exception e) {
                String tmp = "";
            }
        }

Expected behaviour
JVM closes all resources & program doesn't throw java.net.SocketException: Too many open files

Metadata

Metadata

Assignees

No one assigned

    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