Fix another "Too many open file open"

Resources need to be released before creating new NioClient instance during the
reconnecting.
This commit is contained in:
Sheng Yang 2011-05-11 15:30:26 -07:00
parent 053246170c
commit 0c1ad8ac88
2 changed files with 20 additions and 1 deletions

View File

@ -370,7 +370,7 @@ public class Agent implements HandlerFactory, IAgentControl {
do {
_shell.getBackoffAlgorithm().waitBeforeRetry();
s_logger.info("Lost connection to the server. Reconnecting....");
s_logger.info("Lost connection to the server. Dealing with the remaining commands...");
inProgress = _inProgress.get();
if (inProgress > 0) {
@ -379,6 +379,15 @@ public class Agent implements HandlerFactory, IAgentControl {
} while (inProgress > 0);
_connection.stop();
while (_connection.isStartup()){
_shell.getBackoffAlgorithm().waitBeforeRetry();
}
try {
_connection.cleanUp();
} catch (IOException e) {
s_logger.warn("Fail to clean up old connection. " + e);
}
_connection = new NioClient(
"Agent",
_shell.getHost(),

View File

@ -175,6 +175,9 @@ public abstract class NioConnection implements Runnable {
s_logger.warn("Caught an exception but continuing on.", e);
}
}
synchronized(_thread) {
_isStartup = false;
}
}
abstract void init() throws IOException;
@ -550,6 +553,13 @@ public abstract class NioConnection implements Runnable {
_selector.wakeup();
}
/* Release the resource used by the instance */
public void cleanUp() throws IOException {
if (_selector != null && _selector.isOpen()) {
_selector.close();
}
}
public class ChangeRequest {
public static final int REGISTER = 1;
public static final int CHANGEOPS = 2;