Skip to content
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

Disposing WatsonWSServer doesn't free port #38

Closed
joreg opened this issue Oct 14, 2020 · 6 comments
Closed

Disposing WatsonWSServer doesn't free port #38

joreg opened this issue Oct 14, 2020 · 6 comments

Comments

@joreg
Copy link
Contributor

joreg commented Oct 14, 2020

hey joel,

we just discovered that disposing the server doesn't free the port. simple to reproduce using these three lines:

var ws = new WatsonWsServer("127.0.0.1", 6666, false);
ws.Start();
ws.Dispose();

are we missing anything in shutting it down?

@jchristn
Copy link
Owner

jchristn commented Oct 14, 2020

Hi @joreg that should do it. Are you by chance running on .NET Core on Linux/Mac? If so we might be running into this (dotnet/runtime#24025) which references this issue (dotnet/corefx#24809)

Could you let me know the OS and framework you are using?

Edit: my apologies, I thought you were using WatsonWebserver and not WatsonWebsocket. Looking again...

@jchristn
Copy link
Owner

I just noticed my Dispose method was stopping but not closing. Amending the code now and adding a Test.Dispose project to make sure it works as expected.

@jchristn
Copy link
Owner

jchristn commented Oct 14, 2020

Publishing v2.2.0.3 now. Added Test.Dispose project. Per test 3 within the project it definitely appears that there is some lingering issue with the port after stopping or disposing the server. I'm noticing this in both .NET Framework as well as .NET Core, so it may be an issue on my side.

@jchristn
Copy link
Owner

So it appears I have this partially fixed in v2.2.0.4 (publishing momentarily). Here are the results from Test.Dispose using both .NET Framework 4.5.2 and .NET Core App 2.0.

C:\Code\Watson\WatsonWebsocket-2.2>test.dispose\bin\debug\net452\test.dispose
Test 1 with server started: True
Test 2 with server stopped: False
Test 3 with server restarted: True
Test 4 with server disposed: False
Test 5 with server started: True

C:\Code\Watson\WatsonWebsocket-2.2>dotnet test.dispose\bin\debug\netcoreapp2.0\test.dispose.dll
Test 1 with server started: True
Test 2 with server stopped: False
Test 3 with server restarted: False
Test 4 with server disposed: False
Test 5 with server started: True

Test 3 should be true in both cases, but it isn't in .NET Core 2.0.

The same is true with .NET Core 3.1

C:\Code\Watson\WatsonWebsocket-2.2>dotnet test.dispose\bin\debug\netcoreapp3.1\test.dispose.dll
Test 1 with server started: True
Test 2 with server stopped: False
Test 3 with server restarted: False
Test 4 with server disposed: False
Test 5 with server started: True

So I think the issue is the one referenced a few comments ago.

On a side note, I've run into an issue where issuing Stop() is actually terminating existing connections rather than just stopping the listener from accepting new ones.

I may have to migrate away from http.sys soon.

NuGet v2.2.0.4: https://www.nuget.org/packages/WatsonWebsocket/2.2.0.4
Commit: 7b6f7db

@joreg
Copy link
Contributor Author

joreg commented Oct 15, 2020

perfect. works as expected now. thanks!

@jchristn
Copy link
Owner

Glad it's working now @joreg ! I'll close this one and follow the issue referenced above for a later fix. Cheers, Joel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants