Permalink
Browse files

Merge pull request #94 from bgrozev/fix-fd-leak

fix: Propagates close() to the underlying DatagramSocket implementation
  • Loading branch information...
2 parents 72d1b14 + 7c63d52 commit cefd96450947bad93eff9d4b5fc95af25dcb9ae3 @damencho damencho committed on GitHub Jan 11, 2017
@@ -203,8 +203,12 @@ public void close()
}
finally
{
- component.getParentStream().removePairStateChangeListener(this);
- component = null;
+ Component component = this.component;
+ if (component != null)
+ {
+ component.getParentStream().removePairStateChangeListener(this);
+ this.component = null;
+ }
}
}
}
@@ -136,29 +136,37 @@ public boolean isClosed()
@Override
public void close()
{
- if (isClosed())
+ try
{
- return;
+ super.close();
}
- 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)
+ finally
{
- receiveLock.notifyAll();
- }
- synchronized (socketContainersSyncRoot)
- {
- active = null;
- for (SocketContainer container : socketContainers)
+ if (isClosed())
+ {
+ return;
+ }
+ 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];
}
}

0 comments on commit cefd964

Please sign in to comment.