Merge pull request #72 from bgrozev/fix-failiure-to-close

Fixes a failure to close a Socket instance.
This commit is contained in:
George Politis 2016-05-20 13:13:50 -05:00
commit 4f946f38a4

View File

@ -1098,8 +1098,8 @@ public class TcpHarvester
} }
/** /**
* Adds the channels from {@link #newChannels} to {@link #channels} and * Registers the channels from {@link #newChannels} in
* registers them in {@link #readSelector}. * {@link #readSelector}.
*/ */
private void checkForNewChannels() private void checkForNewChannels()
{ {
@ -1126,8 +1126,11 @@ public class TcpHarvester
} }
/** /**
* Checks {@link #channels} for channels which have been added over * Closes any inactive channels registered with {@link #readSelector}.
* {@link #READ_TIMEOUT} milliseconds ago and closes them. * A channel is considered inactive if it hasn't been available for
* reading for
* {@link MuxServerSocketChannelFactory#SOCKET_CHANNEL_READ_TIMEOUT}
* milliseconds.
*/ */
private void cleanup() private void cleanup()
{ {
@ -1223,10 +1226,8 @@ public class TcpHarvester
if (!IceProcessingState.WAITING.equals(state) if (!IceProcessingState.WAITING.equals(state)
&& !IceProcessingState.RUNNING.equals(state)) && !IceProcessingState.RUNNING.equals(state))
{ {
logger.info( throw new IllegalStateException(
"Not adding a socket to an ICE agent with state " "The associated Agent is in state " + state);
+ state);
return;
} }
// Socket to add to the candidate // Socket to add to the candidate
@ -1430,19 +1431,11 @@ public class TcpHarvester
} }
} }
} }
catch (IOException ioe) catch (IOException | StunException | IllegalStateException e)
{ {
logger.info( logger.info(
"Failed to handle TCP socket " "Failed to handle TCP socket "
+ channel.channel.socket() + ": " + ioe); + channel.channel.socket() + ": " + e.getMessage());
key.cancel();
closeNoExceptions(channel.channel);
}
catch (StunException se)
{
logger.info(
"Failed to handle TCP socket "
+ channel.channel.socket() + ": " + se);
key.cancel(); key.cancel();
closeNoExceptions(channel.channel); closeNoExceptions(channel.channel);
} }