Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUDP port stays open when DNS query runs into a timeout or error #110
Comments
|
Hi, When we get an IO exception, then the channel does not get closed. ` public void processReadyKey(SelectionKey key) {
` |
|
I think, the channel should be closed in the catch (IOException e) block. |
|
Yes, you're probably right. I need to verify the behavior, which might take me a while. |
|
I added some code to close the channel in the above situation and it is now working fine for me. However, I am not sure, whether this are all error conditions where you should close the datagram socket... |
|
Verifying is pretty easy. Run in a loop DNS requests against an IP that doesn't have a DNS server installed. You will get an error and after a while, you will have plenty of open UDP datagram sockets. |
|
If you already changed this, would you mind creating a pull request? Ideally including a unit test that verifies your fix is working. |
|
Hi, this is my modified version of the NioUdpClient.java based on 3.1.0 release. I have added a block to close the channels. I was testing it by checking the list of open UDP ports using the netstat command. Don't know how you might automate that in a unit test.... |
In our application, we have a little piece of code that checks whether a target computer has a DNS service installed. For that purpose, we send a DNS query to the target computer. When the target server hosts a DNS service, then we receive a proper response and everything is fine. However, when there is an error (timeout or IOException), then we get the correct error message, but a UDP port stays open.
When we perform 1000 queries to IP addresses which don't have a DNS server up and running, then we end up with 1000 open UDP ports until the process terminates. After testing even more, the system runs out of ports.
We run our code currently with dnsjava-3.0.2, but we also tested the latest release 3.1.0 with the same result. We are running our project with OpenJDK 13 on Windows. We check the open ports from the command line via 'netstat.exe -a -n -b | find "UDP"'
This here is basically our source code. The parameter "address" corresponds to the IP address where we would like to check whether a valid DNS server is running on that IP address:
public DiscoveryProtocolStatus validateDnsServer(IPAddress address) {
DiscoveryProtocolStatus retval = DiscoveryProtocolStatus.NotTested;
}