mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
02.48.2013 314e6b708cf098b0ca428093eeff507674055189
Fix OPENDJ-1043: Worker Thread was interrupted while waiting for new work while shutting down 

Don't block forever when publishing changes to the queue. Instead periodically check to see if the session has been closed and the socket writer (consumer) has been terminated.
1 files modified
26 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/Session.java 26 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/replication/protocol/Session.java
@@ -36,6 +36,7 @@
import java.net.Socket;
import java.net.SocketException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
@@ -333,14 +334,25 @@
    final byte[] buffer = msg.getBytes(protocolVersion);
    if (isRunning.get())
    {
      try {
        sendQueue.put(buffer);
      while (!closeInitiated)
      {
        try
        {
          // Avoid blocking forever so that we can check for session closure.
          if (sendQueue.offer(buffer, 100, TimeUnit.MILLISECONDS))
          {
            return;
          }
        }
        catch (final InterruptedException e)
        {
          setSessionError(e);
          throw new IOException(e.getMessage());
        }
      }
      catch (final InterruptedException e) {
        setSessionError(e);
        throw new IOException(e.getMessage());
      }
    } else {
    }
    else
    {
      send(buffer);
    }
  }