Merge pull request #863 from borisroman/CLOUDSTACK-8883 [4.6][BLOCKER]CLOUDSTACK-8883: Resolved connect/reconnect issue.Hi!
@wilderrodrigues by implementing Callable you switched a couple of methods and fields. I switched them some more! The reason why the Agent wouldn't reconnect was due to two facts. Problem 1: Selector was blocking. In the while loop at [1] _selector.select(); was blocking when the connection was lost. This means at [2] _isStartup = false; was never excecuted. Therefore at [3] the call to isStartup() always returned true resulting in an infinite loop. Resolution 1: Move the call to cleanUp() [4] before checking if isStartup() has turned to false. cleanUp() will close() the _selector resulting in _isStartup to be set to false. Problem 2: Setting _isStartup & _isRunning to true when init() throwed an unchecked exception (ConnectException). The exception was nicely caught, but only logged. No action was taken! Resulting in _isStartup & _isRunning being set to true. Resulting in the fact the Agent thought it was connected successfully, though it wasn't. Resolution 2: Adding return to the catch statement [5]. This way _isStartup & _isRunning aren't set to true. Steps to test: 1. Deploy ACS. 2. Try all combinations of stopping/starting managment server/agent. [1]https://github.com/borisroman/cloudstack/blob/b34f86c8d55a1cfc057585eab4db0fa2d98a7b3e/utils/src/main/java/com/cloud/utils/nio/NioConnection.java#L128 [2]https://github.com/borisroman/cloudstack/blob/b34f86c8d55a1cfc057585eab4db0fa2d98a7b3e/utils/src/main/java/com/cloud/utils/nio/NioConnection.java#L176 [3]https://github.com/borisroman/cloudstack/blob/b34f86c8d55a1cfc057585eab4db0fa2d98a7b3e/agent/src/com/cloud/agent/Agent.java#L404 [4]https://github.com/borisroman/cloudstack/blob/b34f86c8d55a1cfc057585eab4db0fa2d98a7b3e/agent/src/com/cloud/agent/Agent.java#L399 [5]https://github.com/borisroman/cloudstack/blob/b34f86c8d55a1cfc057585eab4db0fa2d98a7b3e/utils/src/main/java/com/cloud/utils/nio/NioConnection.java#L91 * pr/863: Added return statement to stop start() if there has been an ConnectException. Call cleanUp() before looping isStartup(). Signed-off-by: Rajani Karuturi <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1a474374 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1a474374 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1a474374 Branch: refs/heads/master Commit: 1a474374b9c936ed40a1d83ce8b75ea189f23399 Parents: 86325cb b34f86c Author: Rajani Karuturi <[email protected]> Authored: Wed Sep 23 11:21:39 2015 +0530 Committer: Rajani Karuturi <[email protected]> Committed: Wed Sep 23 11:21:41 2015 +0530 ---------------------------------------------------------------------- agent/src/com/cloud/agent/Agent.java | 8 +++++--- utils/src/main/java/com/cloud/utils/nio/NioConnection.java | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) ----------------------------------------------------------------------
