SocketUtils considers a port available if a ConnectException is thrown during connect attempt #3726
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This might help out with #3670
Currently,
SocketUtils
considers a port available if an attempt to connect to it fails. This isn't always the case. For example, a timeout might indicate that something is using the port but did not respond to the connection in time. I'm sure there are other situations where an exception might mean that the port is not available.I'm not convinced that what I've proposed is actually the best approach here, but I think it is more correct than what we have now. I believe that a port that isn't in use will always throw a
java.net.ConnectException
with a message of "Connection refused".I was thinking that it may be more conclusive to try to listen on the port, or maybe listen and send a short message through to determine if it is actually available, but I suspect that will be a lot slower than what we have and I'm also concerned that the port may not be cleaned up in time for the caller to use it for something else.