提交 78d5bf60 编写于 作者: I igerasim

7011441: jndi/ldap/Connection.java needs to avoid spurious wakeup

Reviewed-by: dholmes
上级 7beb1017
...@@ -439,9 +439,14 @@ public final class Connection implements Runnable { ...@@ -439,9 +439,14 @@ public final class Connection implements Runnable {
BerDecoder readReply(LdapRequest ldr) BerDecoder readReply(LdapRequest ldr)
throws IOException, NamingException { throws IOException, NamingException {
BerDecoder rber; BerDecoder rber;
boolean waited = false;
while (((rber = ldr.getReplyBer()) == null) && !waited) { // Track down elapsed time to workaround spurious wakeups
long elapsedMilli = 0;
long elapsedNano = 0;
while (((rber = ldr.getReplyBer()) == null) &&
(readTimeout <= 0 || elapsedMilli < readTimeout))
{
try { try {
// If socket closed, don't even try // If socket closed, don't even try
synchronized (this) { synchronized (this) {
...@@ -455,11 +460,15 @@ public final class Connection implements Runnable { ...@@ -455,11 +460,15 @@ public final class Connection implements Runnable {
rber = ldr.getReplyBer(); rber = ldr.getReplyBer();
if (rber == null) { if (rber == null) {
if (readTimeout > 0) { // Socket read timeout is specified if (readTimeout > 0) { // Socket read timeout is specified
long beginNano = System.nanoTime();
// will be woken up before readTimeout only if reply is // will be woken up before readTimeout if reply is
// available // available
ldr.wait(readTimeout); ldr.wait(readTimeout - elapsedMilli);
waited = true; elapsedNano += (System.nanoTime() - beginNano);
elapsedMilli += elapsedNano / 1000_000;
elapsedNano %= 1000_000;
} else { } else {
// no timeout is set so we wait infinitely until // no timeout is set so we wait infinitely until
// a response is received // a response is received
...@@ -476,7 +485,7 @@ public final class Connection implements Runnable { ...@@ -476,7 +485,7 @@ public final class Connection implements Runnable {
} }
} }
if ((rber == null) && waited) { if ((rber == null) && (elapsedMilli >= readTimeout)) {
abandonRequest(ldr, null); abandonRequest(ldr, null);
throw new NamingException("LDAP response read timed out, timeout used:" throw new NamingException("LDAP response read timed out, timeout used:"
+ readTimeout + "ms." ); + readTimeout + "ms." );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册