Skip to content

Commit

Permalink
fix: Propagates close() to the underlying DatagramSocket implementation
Browse files Browse the repository at this point in the history
fixing a leak of fd's while the the objects waiting to be finalized.
  • Loading branch information
bgrozev committed Jan 11, 2017
1 parent 72d1b14 commit 7c63d52
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/ice4j/ice/ComponentSocket.java
Expand Up @@ -203,8 +203,12 @@ public void close()
} }
finally finally
{ {
component.getParentStream().removePairStateChangeListener(this); Component component = this.component;
component = null; if (component != null)
{
component.getParentStream().removePairStateChangeListener(this);
this.component = null;
}
} }
} }
} }
42 changes: 25 additions & 17 deletions src/main/java/org/ice4j/socket/MergingDatagramSocket.java
Expand Up @@ -136,29 +136,37 @@ public boolean isClosed()
@Override @Override
public void close() public void close()
{ {
if (isClosed()) try
{ {
return; super.close();
} }
closed = true; finally
logger.info("Closing.");

// XXX do we want to risk obtaining the lock here, or should we just
// let any thread in receive() find out about the close after it's next
// timeout?
synchronized (receiveLock)
{ {
receiveLock.notifyAll();
}


synchronized (socketContainersSyncRoot) if (isClosed())
{ {
active = null; return;
for (SocketContainer container : socketContainers) }
closed = true;
logger.info("Closing.");

// XXX do we want to risk obtaining the lock here, or should we just
// let any thread in receive() find out about the close after it's
// next timeout?
synchronized (receiveLock)
{
receiveLock.notifyAll();
}

synchronized (socketContainersSyncRoot)
{ {
container.close(false); active = null;
for (SocketContainer container : socketContainers)
{
container.close(false);
}
socketContainers = new SocketContainer[0];
} }
socketContainers = new SocketContainer[0];
} }
} }


Expand Down

0 comments on commit 7c63d52

Please sign in to comment.