From e4f5534b3d9572ffb5731e6ceda253bc65a3ee59 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Fri, 20 May 2016 11:35:00 -0500 Subject: [PATCH 1/2] Minor fixes to the documentation. --- src/main/java/org/ice4j/ice/harvest/TcpHarvester.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java index d1f3dff..6f83fc8 100644 --- a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java @@ -1098,8 +1098,8 @@ public class TcpHarvester } /** - * Adds the channels from {@link #newChannels} to {@link #channels} and - * registers them in {@link #readSelector}. + * Registers the channels from {@link #newChannels} in + * {@link #readSelector}. */ private void checkForNewChannels() { @@ -1126,8 +1126,11 @@ public class TcpHarvester } /** - * Checks {@link #channels} for channels which have been added over - * {@link #READ_TIMEOUT} milliseconds ago and closes them. + * Closes any inactive channels registered with {@link #readSelector}. + * A channel is considered inactive if it hasn't been available for + * reading for + * {@link MuxServerSocketChannelFactory#SOCKET_CHANNEL_READ_TIMEOUT} + * milliseconds. */ private void cleanup() { From 568ace382bfbdf62c05d84b581e4487c3e7dadb5 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Fri, 20 May 2016 11:38:22 -0500 Subject: [PATCH 2/2] Fixes a failure to close a Socket instance. Makes sure that Socket instances which are discarded because they are only added after the corresponding ICE Agent has moved away from the WAITING or RUNNING state are closed. This prevents a file descriptor leak, since Socket instances which are not closed (even after they are garbage collected) leave behind sockets in state CLOSE_WAIT. --- .../org/ice4j/ice/harvest/TcpHarvester.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java index 6f83fc8..fea4e97 100644 --- a/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/TcpHarvester.java @@ -1226,10 +1226,8 @@ public class TcpHarvester if (!IceProcessingState.WAITING.equals(state) && !IceProcessingState.RUNNING.equals(state)) { - logger.info( - "Not adding a socket to an ICE agent with state " - + state); - return; + throw new IllegalStateException( + "The associated Agent is in state " + state); } // Socket to add to the candidate @@ -1433,19 +1431,11 @@ public class TcpHarvester } } } - catch (IOException ioe) + catch (IOException | StunException | IllegalStateException e) { logger.info( "Failed to handle TCP socket " - + channel.channel.socket() + ": " + ioe); - key.cancel(); - closeNoExceptions(channel.channel); - } - catch (StunException se) - { - logger.info( - "Failed to handle TCP socket " - + channel.channel.socket() + ": " + se); + + channel.channel.socket() + ": " + e.getMessage()); key.cancel(); closeNoExceptions(channel.channel); }