提交 63caf01b 编写于 作者: R robm

8129957: Deadlock in JNDI LDAP implementation when closing the LDAP context

Reviewed-by: vinnie
上级 37b07e03
...@@ -494,7 +494,6 @@ public final class LdapClient implements PooledConnection { ...@@ -494,7 +494,6 @@ public final class LdapClient implements PooledConnection {
*/ */
void processConnectionClosure() { void processConnectionClosure() {
// Notify listeners // Notify listeners
synchronized (unsolicited) {
if (unsolicited.size() > 0) { if (unsolicited.size() > 0) {
String msg; String msg;
if (conn != null) { if (conn != null) {
...@@ -504,7 +503,6 @@ public final class LdapClient implements PooledConnection { ...@@ -504,7 +503,6 @@ public final class LdapClient implements PooledConnection {
} }
notifyUnsolicited(new CommunicationException(msg)); notifyUnsolicited(new CommunicationException(msg));
} }
}
// Remove from pool // Remove from pool
if (pooled) { if (pooled) {
...@@ -1499,13 +1497,8 @@ public final class LdapClient implements PooledConnection { ...@@ -1499,13 +1497,8 @@ public final class LdapClient implements PooledConnection {
if (debug > 0) { if (debug > 0) {
System.err.println("LdapClient.removeUnsolicited" + ctx); System.err.println("LdapClient.removeUnsolicited" + ctx);
} }
synchronized (unsolicited) {
if (unsolicited.size() == 0) {
return;
}
unsolicited.removeElement(ctx); unsolicited.removeElement(ctx);
} }
}
// NOTE: Cannot be synchronized because this is called asynchronously // NOTE: Cannot be synchronized because this is called asynchronously
// by the reader thread in Connection. Instead, sync on 'unsolicited' Vector. // by the reader thread in Connection. Instead, sync on 'unsolicited' Vector.
...@@ -1513,7 +1506,6 @@ public final class LdapClient implements PooledConnection { ...@@ -1513,7 +1506,6 @@ public final class LdapClient implements PooledConnection {
if (debug > 0) { if (debug > 0) {
System.err.println("LdapClient.processUnsolicited"); System.err.println("LdapClient.processUnsolicited");
} }
synchronized (unsolicited) {
try { try {
// Parse the response // Parse the response
LdapResult res = new LdapResult(); LdapResult res = new LdapResult();
...@@ -1532,11 +1524,17 @@ public final class LdapClient implements PooledConnection { ...@@ -1532,11 +1524,17 @@ public final class LdapClient implements PooledConnection {
forceClose(pooled); forceClose(pooled);
} }
LdapCtx first = null;
UnsolicitedNotification notice = null;
synchronized (unsolicited) {
if (unsolicited.size() > 0) { if (unsolicited.size() > 0) {
first = unsolicited.elementAt(0);
// Create an UnsolicitedNotification using the parsed data // Create an UnsolicitedNotification using the parsed data
// Need a 'ctx' object because we want to use the context's // Need a 'ctx' object because we want to use the context's
// list of provider control factories. // list of provider control factories.
UnsolicitedNotification notice = new UnsolicitedResponseImpl( notice = new UnsolicitedResponseImpl(
res.extensionId, res.extensionId,
res.extensionValue, res.extensionValue,
res.referrals, res.referrals,
...@@ -1544,9 +1542,12 @@ public final class LdapClient implements PooledConnection { ...@@ -1544,9 +1542,12 @@ public final class LdapClient implements PooledConnection {
res.errorMessage, res.errorMessage,
res.matchedDN, res.matchedDN,
(res.resControls != null) ? (res.resControls != null) ?
unsolicited.elementAt(0).convertControls(res.resControls) : first.convertControls(res.resControls) :
null); null);
}
}
if (notice != null) {
// Fire UnsolicitedNotification events to listeners // Fire UnsolicitedNotification events to listeners
notifyUnsolicited(notice); notifyUnsolicited(notice);
...@@ -1558,9 +1559,6 @@ public final class LdapClient implements PooledConnection { ...@@ -1558,9 +1559,6 @@ public final class LdapClient implements PooledConnection {
} }
} }
} catch (IOException e) { } catch (IOException e) {
if (unsolicited.size() == 0)
return; // no one registered; ignore
NamingException ne = new CommunicationException( NamingException ne = new CommunicationException(
"Problem parsing unsolicited notification"); "Problem parsing unsolicited notification");
ne.setRootCause(e); ne.setRootCause(e);
...@@ -1571,17 +1569,20 @@ public final class LdapClient implements PooledConnection { ...@@ -1571,17 +1569,20 @@ public final class LdapClient implements PooledConnection {
notifyUnsolicited(e); notifyUnsolicited(e);
} }
} }
}
private void notifyUnsolicited(Object e) { private void notifyUnsolicited(Object e) {
for (int i = 0; i < unsolicited.size(); i++) { Vector<LdapCtx> unsolicitedCopy;
unsolicited.elementAt(i).fireUnsolicited(e); synchronized (unsolicited) {
} unsolicitedCopy = new Vector<>(unsolicited);
if (e instanceof NamingException) { if (e instanceof NamingException) {
unsolicited.setSize(0); // no more listeners after exception unsolicited.setSize(0); // no more listeners after exception
} }
} }
for (int i = 0; i < unsolicitedCopy.size(); i++) {
unsolicitedCopy.elementAt(i).fireUnsolicited(e);
}
}
private void ensureOpen() throws IOException { private void ensureOpen() throws IOException {
if (conn == null || !conn.useable) { if (conn == null || !conn.useable) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册