fix: Propagates close() to the underlying DatagramSocket implementation

fixing a leak of fd's while the the objects waiting to be finalized.
This commit is contained in:
Boris Grozev 2017-01-11 12:30:30 -06:00
parent 72d1b1441c
commit 7c63d5202c
2 changed files with 31 additions and 19 deletions

View File

@ -203,8 +203,12 @@ public class ComponentSocket
}
finally
{
component.getParentStream().removePairStateChangeListener(this);
component = null;
Component component = this.component;
if (component != null)
{
component.getParentStream().removePairStateChangeListener(this);
this.component = null;
}
}
}
}

View File

@ -136,29 +136,37 @@ public class MergingDatagramSocket
@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())
{
container.close(false);
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)
{
active = null;
for (SocketContainer container : socketContainers)
{
container.close(false);
}
socketContainers = new SocketContainer[0];
}
socketContainers = new SocketContainer[0];
}
}