RFR: 8313657 : com.sun.jndi.ldap.Connection.cleanup does not close connections on SocketTimeoutErrors

Mark Sheppard msheppar at openjdk.org
Fri Aug 4 15:23:33 UTC 2023


On Thu, 3 Aug 2023 17:32:43 GMT, Weibing Xiao <duke at openjdk.org> wrote:

> com.sun.jndi.ldap.Connection::leanup does not close the underlying socket if the is an IOException generation when the output stream was flushing the buffer.
> 
> Please refer to the bug https://bugs.openjdk.org/browse/JDK-8313657.

why not restructure the finally block a little ... refactor extract methods
flushOutputStream, 
closeConnectionSocket 
... should the outputStream be closed in this finally block, also?

                } finally {
                    flushOutputStream(outStream);
                    closeConnectionSocket(sock);
                    try {
                        unpauseReader();
                    } catch (IOException ie) {
                        if (debug)
                            System.err.println("Connection.cleanup: problem with unpuaseReader " + ie);
                    }
  ...


    private void flushOutputStream (OutputStream outputStream) {
        try {
            outStream.flush();
            outStream.close();
        } catch (IOException ioEx) {
            if (debug)
                System.err.println("Connection.flushOutputStream: OutputStream flush or close problem " + ioEx);
        }
    }
    
    private void closeConnectionSocket (Socket sock) {
        //bug 8313657, socket not closed util GC running
        try {
            sock.close();
        } catch (IOException ioEx) {
            if (debug)
                System.err.println("ConnectioncloseConnectioSocket: problem closing socket: " + ioEx);
        }
    }

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15143#issuecomment-1665777500


More information about the core-libs-dev mailing list