Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ea2d289
8362268 : NPE thrown from SASL GSSAPI impl on Java 11+ when TLS is us…
weibxiao Jul 30, 2025
c44693c
Revert "8362268 : NPE thrown from SASL GSSAPI impl on Java 11+ when T…
weibxiao Jul 30, 2025
20eba8f
8362268 : NPE thrown from SASL GSSAPI impl on Java 11+ when TLS is us…
weibxiao Jul 30, 2025
1bd7c0f
added missing file
weibxiao Jul 30, 2025
c7c0662
added missing file
weibxiao Jul 30, 2025
3b9b1ba
Merge branch 'JDK-8362268' of https://github.com/weibxiao/jdk into JD…
weibxiao Aug 1, 2025
a33666e
revert javax.security.sasl.maxbuffer
weibxiao Aug 1, 2025
f5a13b0
Merge branch 'master' of https://github.com/openjdk/jdk into JDK-8362268
weibxiao Aug 6, 2025
0852897
revert the code
weibxiao Aug 7, 2025
666dfe0
close open resource in LDAP client
weibxiao Sep 2, 2025
765a467
removed the commented out code
weibxiao Sep 2, 2025
dd21da3
remove unused code
weibxiao Sep 2, 2025
e849f21
Merge branch 'master' of https://github.com/openjdk/jdk
weibxiao Sep 11, 2025
0d6e178
Merge branch 'master' of github.com:openjdk/jdk
weibxiao Sep 11, 2025
ae1ca7d
Merge branch 'master' of github.com:openjdk/jdk
weibxiao Sep 12, 2025
c3a135f
Merge branch 'master' of github.com:openjdk/jdk
weibxiao Sep 30, 2025
95228ac
Merge branch 'master' of github.com:openjdk/jdk
weibxiao Sep 30, 2025
ee8ebf6
Merge branch 'openjdk:master' into master
weibxiao Sep 30, 2025
a92365a
Merge branch 'openjdk:master' into master
weibxiao Oct 2, 2025
77b418d
update the code
weibxiao Oct 2, 2025
fab7226
Merge branch 'openjdk:master' into master
weibxiao Oct 2, 2025
eb7042b
Merge branch 'master' of github.com:openjdk/jdk
weibxiao Oct 2, 2025
0ae8e02
Merge branch 'master' of github.com:weibxiao/jdk
weibxiao Oct 2, 2025
d0601e6
Merge branch 'master' into JDK-8362268
weibxiao Oct 2, 2025
9b71e67
Merge branch 'master' of github.com:openjdk/jdk into JDK-8362268
weibxiao Oct 14, 2025
4dd2066
update the code
weibxiao Oct 15, 2025
c69d484
add new method to handle connection cleaning
weibxiao Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,10 @@ void cleanup(Control[] reqCtls, boolean notifyParent) {
}
} finally {

flushAndCloseOutputStream();
flushOutputStream();
// 8313657 socket is not closed until GC is run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth keeping a comment here about why sock is not closed, or at least mentioning 8362268?

closeOpenedSocket(sock);
// due to the bug 8362268, the closure of the resource is moved to LdapClient.java
//closeOpenedSocket(sock);
tryUnpauseReader();

if (!notifyParent) {
Expand All @@ -673,7 +674,6 @@ void cleanup(Control[] reqCtls, boolean notifyParent) {
tlsHandshakeListener.tlsHandshakeCompleted.cancel(false);
}
}
sock = null;
}
nparent = notifyParent;
}
Expand All @@ -693,19 +693,13 @@ void cleanup(Control[] reqCtls, boolean notifyParent) {
}

// flush and close output stream
private void flushAndCloseOutputStream() {
private void flushOutputStream() {
try {
outStream.flush();
} catch (IOException ioEx) {
if (debug)
System.err.println("Connection.flushOutputStream: OutputStream flush problem " + ioEx);
}
try {
outStream.close();
} catch (IOException ioEx) {
if (debug)
System.err.println("Connection.closeOutputStream: OutputStream close problem " + ioEx);
}
}

// close socket
Expand All @@ -720,7 +714,26 @@ private void closeOpenedSocket(Socket socket) {
}
}
}
void cleanupAndClose(Control[] reqCtls) {
lock.lock();
try {

cleanup(reqCtls, false);

// 8313657 socket is not closed until GC is run
// it caused the bug 8362268, hence moved here
if (outStream != null) {
outStream.close();
}
if (!sock.isClosed()) {
sock.close();
}
} catch (IOException ignored) {
// we're closing, ignore IO.
} finally {
lock.unlock();
}
}
// unpause reader
private void tryUnpauseReader() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,12 @@ void close(Control[] reqCtls, boolean hardClose) {
if (debug > 0) System.err.println("LdapClient: closed connection " + this);
if (!pooled) {
// Not being pooled; continue with closing
conn.cleanup(reqCtls, false);
conn.cleanupAndClose(reqCtls);
} else {
// Pooled
// Is this a real close or a request to return conn to pool
if (hardClose) {
conn.cleanup(reqCtls, false);
conn.cleanupAndClose(reqCtls);
pcb.removePooledConnection(this);
} else {
pcb.releasePooledConnection(this);
Expand All @@ -477,6 +477,7 @@ void close(Control[] reqCtls, boolean hardClose) {
}
}


// NOTE: Should NOT be synchronized otherwise won't be able to close
private void forceClose(boolean cleanPool) {
referenceCount = 0; // force closing of connection
Expand Down
45 changes: 1 addition & 44 deletions test/jdk/com/sun/jndi/ldap/SocketCloseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
import javax.net.SocketFactory;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Hashtable;

import jdk.test.lib.process.OutputAnalyzer;
Expand Down Expand Up @@ -65,6 +61,7 @@ public void runCloseSocketScenario() throws Exception {
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldap://localhost:1389/o=example");
props.put("java.naming.ldap.factory.socket", CustomSocketFactory.class.getName());
props.put("com.sun.jndi.ldap.connect.timeout", 100+"");
try {
final DirContext ctx = new InitialDirContext(props);
} catch (Exception e) {
Expand Down Expand Up @@ -112,48 +109,8 @@ public Socket createSocket(InetAddress address, int port,
}
}

private static class LdapInputStream extends InputStream {
private ByteArrayInputStream bos;

public LdapInputStream() {
}

@Override
public int read() throws IOException {
bos = new ByteArrayInputStream(BIND_RESPONSE);
return bos.read();
}
}

private static class LdapOutputStream extends OutputStream {

@Override
public void write(int b) throws IOException {
System.out.println("output stream writing");
}

@Override
public void flush() throws IOException {
System.out.println(BAD_FLUSH);
throw new IOException(BAD_FLUSH);
}
}

private static class CustomSocket extends Socket {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: could you please cleanup unused imports after this change?

private int closeMethodCalled = 0;
private LdapOutputStream output = new LdapOutputStream();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are local objects which are no longer used after removal of this. I'd personally remove the private static class LdapInputStream extends InputStream { and private static class LdapOutputStream extends OutputStream { further down the file

private LdapInputStream input = new LdapInputStream();

public void connect(SocketAddress address, int timeout) {
}

public InputStream getInputStream() {
return input;
}

public OutputStream getOutputStream() {
return output;
}

public int closeMethodCalledCount() {
return closeMethodCalled;
Expand Down