Fixed ephemeral port duplication which might be caused by deserialization

This commit is contained in:
Trustin Lee 2009-02-09 05:07:53 +00:00
parent 73e8954239
commit 0fc8977bf2

View File

@ -56,7 +56,13 @@ public final class LocalAddress extends SocketAddress implements Comparable<Loca
} }
public static LocalAddress newEphemeralInstance() { public static LocalAddress newEphemeralInstance() {
return getInstance("ephemeral-" + nextEphemeralPort.incrementAndGet()); for (;;) {
String id = "ephemeral-" + nextEphemeralPort.incrementAndGet();
LocalAddress a = new LocalAddress(id);
if (addresses.putIfAbsent(id, a) == null) {
return a;
}
}
} }
private final String id; private final String id;