Skip to content

Commit b6e5d03

Browse files
committed
fix: Fixes a bug which prevents the socket to close.
After the delegate is closed, isClosed() would return true, which would prevent the DatagramSocket instance (super) from actually closing and releasing its resources.
1 parent e472f6a commit b6e5d03

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ static boolean logNonStun(long numOfPacket)
115115
*/
116116
private long nbSentPackets = 0;
117117

118+
/**
119+
* Whether this socket has been closed.
120+
*/
121+
private boolean closed = false;
122+
118123
/**
119124
* Initializes a new <tt>DelegatingDatagramSocket</tt> instance and binds it
120125
* to any available port on the local host machine. The socket will be
@@ -282,10 +287,14 @@ public void bind(SocketAddress addr)
282287
@Override
283288
public void close()
284289
{
290+
// We want both #delegate and super to actually get closed (and release
291+
// the FDs which they hold). But super will not close unless isClosed()
292+
// returns false. So we update the #closed flag last.
285293
if (delegate != null)
286294
delegate.close();
287295

288296
super.close();
297+
closed = true;
289298
}
290299

291300
/**
@@ -610,7 +619,7 @@ public boolean isBound()
610619
@Override
611620
public boolean isClosed()
612621
{
613-
return (delegate == null) ? super.isClosed() : delegate.isClosed();
622+
return closed;
614623
}
615624

616625
/**

0 commit comments

Comments
 (0)