-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible port lock situation when trying to connect to a local, not running, NATS server #847
Comments
I don't see it. Why would Connection.cs#L386 touch any port at all, and why would the ensuing code touch any port other than the specified port. If it does, and it's inside the TcpClient code, this would affect every C# project ever. Do you have any local name resolution in the environment? |
Hi @scottf, I created a small console app that simulates this problem |
After some further investigation, I noticed that this issue does not happen on an initial connect, only on a reconnect. |
Reproduction using just the NATS.Client library: https://gist.github.com/LaurensVergote/ba4b4ea1825f2ff5fed3d1aee9214dd8 |
Observed behavior
When creating a connection to a local hostname, it's possible that the TcpClient created will grab the target port as its local port. This seems to result in a connection successfully being established and the client application grabbing the port, making it impossible for the nats server to ever start up later on using that port.
output of netstat (table format for readability):
Possible solutions:
Comments:
While I'm not 100% certain on the root cause of this, the above description is my best educated guess on why this would happen.
I've only noticed it on dev machines that run the host process, which tries to connect every 1 second to NATS, and while the target local nats-server, is not running.
This results in not being able to start the local nats-server anymore.
I know it's very niche but it's better if its noted down at least, even if there's no intent to fix it or spend time on it.
Expected behavior
The NATS client does not use the target endpoint's port as the local endpoint's when connecting with a local endpoint
Server and client version
Server version not relevant.
client version: 1.1.1
Host environment
Running on Windows 10 Enterprise, loading the NATS client library as .netstandard 2.0 from a .NET 6.0 host process.
Steps to reproduce
Continually call Connect until you randomly get the target's endpoint port as your local endpoint's port.
The text was updated successfully, but these errors were encountered: