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
Stopping HttpListener doesn't free up address in use for some time on macOS (System.Net.HttpListenerException: Address already in use) #24025
Comments
This issue does not repro on Windows with .NET Framework. |
Without being a macOs network expert, my first thought is that you are running into TIME_WAIT and MSL issues. This is a good StackOverflow discussion of what they mean. When you close a connection, the OS waits "a while" for any stray packets that might have been delayed on the network to either arrive (and be thrown out) or to time out on the network (which also involves them being thrown out). In all case, we don't want those stray packets to arrive on the destination machine and possibly be considered to be part of an new connection! The amount of time the OS will wait is 2*msl. According to this ServerFault post, MSL on macOs Lion is 15 seconds. That implies that you have to wait for at least 30 seconds to reuse the server port. Can you try either bumping up the time, or switching the port to different values? |
I appreciate this. However, I'm wondering how frameworks like Node.js Express.js and ASP.NET Core are handing this. I'm able to stop and start their webservers without any issue. Why does it work for those but not HttpListener on .NET Core? |
Presumably this is https://github.com/dotnet/corefx/issues/24562 / dotnet/corefx#24809 |
I thought it might be related to those but wasn't sure since those didn't mention HttpListener. Is this then a dupe of one of those, you think? |
@tylerl0706 yes, I believe that is the root cause of the issue you are seeing. |
Dup of #23803 / dotnet/corefx#24809. Thanks for reporting. |
Apologies if I missed it above, but is there a fix for this issue with HttpListener on OS X? |
@dhowe , can't speak for OS X, but the issue appears to be fixed in the latest dotnet core 2.1 Debian release (tested against docker image microsoft/dotnet:2.1-runtime). Try switching to the 2.1 framework and see if it resolves the issue for you on OS X. |
Haven't messed with this in some time so I'm good. 👍 |
Unless something has changed very recently, this is issue is NOT resolved. I have since switched to debian where the issue (as @bgottfried91 mentions above) does not appear to exist. On OSX the only workaround I had found was to use random ports. |
@dhowe are you using 2.1? |
dotnet 2.0 due to compatibility requirements |
The fix is not in 2.0. Using 2.1 you shouldn't see this. 2.1 will be released soon-ish. |
I'm receiving the following error:
I am writing an http server using HttpListener (I need to use HttpListener) and I run into this exception after starting and stoping and starting the server.
Here is my (watered down) library:
I've also tried this with
listener.Close()
And the file I'm using to verify this behavior is:
I noticed there was this issue with "Address already in use" issues but it seemed unrelated to HttpListener class so I opened this.
This is using the .NET Command Line Tools - 2.0.0
macOS - v10.12.6 (16G29) aka Sierra
Please let me know if there's any additional info I can provide.
The text was updated successfully, but these errors were encountered: