Skip to content

leak udp port as not catch InternalError when "selector.wakeup();"  #318

@goodjin

Description

@goodjin

in NioUdpClient.sendrecv method, when IOException happened,channel will be closed,so the os can reuse the udp port.
but, when execute "selector.wakeup();" , it may throw a InternalError which is a Throwable Error, not a IOException.
thus the channel will not be closed any more, it will occupy the udp port forever, when times on, there will no port can be used.

below is the code:

static CompletableFuture<byte[]> sendrecv(
// some other code here
try {
final Selector selector = selector();
channel = DatagramChannel.open();
channel.configureBlocking(false);

  // some other code here

  channel.connect(remote);
  pendingTransactions.add(t);
  registrationQueue.add(t);
  selector.wakeup();
} catch (IOException e) {
  if (channel != null) {
    try {
      channel.close();
    } catch (IOException ioe) {
      // ignore
    }
  }
  f.completeExceptionally(e);
}

return f;

}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions