mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Port is left open after process terminates #242
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @arnonax on GitHub (Jan 22, 2020).
I started using WireMock.net in my tests, but occasionally when I run the test I get an exception:
Clearly the fault is in the previous run which didn't close the port. Using TCPView from SysInternals, I see that the process which holds that port is "" and I cannot kill it, nor find the PID in Task Manager nor able to kill it using
taskkill. The only solution I found is to restart or at least to log-off/log-on to Windows. I searched the Web (and StackOverflow) in order to understand how can a process still hold a port even though it's been terminated, but didn't find any useful explanation.Because it only happens occasionally, and because each time it happens it requires a restart, it makes it a nightmare to debug and investigate. It seems though that it happens when the sending application crashes while sending or receiving a message, but I'm not sure.
I would like to know:
Thanks in advance,
Arnon.
@StefH commented on GitHub (Jan 22, 2020):
It probably has to do with tcp port exhaustion
See this page https://docs.microsoft.com/en-us/windows/client-management/troubleshoot-tcpip-port-exhaust and you can find many like this.
When using WireMock in unit-tests, it's adviced to not define a port by yourself, but just let WireMock find a free port. (I'm not sure if you alreay are doing this?)
@arnonax commented on GitHub (Jan 22, 2020):
@StefH , I don't think so, because I use a fixed port (I also tried to let WireMock choose a port, but the result was the same). Also, both from the error message and from TCPView it's pretty clear that problem is that the previously run process didn't close the port.
@StefH commented on GitHub (Jan 22, 2020):
If you use a fixed port, the only thing you can do it wait 30 seconds / 60 seconds.
Else if WireMock determines the port, this should work almost always ok, (It's not 100% I think)
@arnonax commented on GitHub (Jan 22, 2020):
Unfortunately it doesn't help either. I tried waiting much longer than that until I had to restart.
However, in the last few minutes I had the issue again, and just closed few applications, including the client process, and it released the port. Next time it will happen, I'll try to terminate only the client process to make sure that this is indeed the culprit. It won't answer all the questions, but at least I'll no longer need to restart Windows in order to recover.
@arnonax commented on GitHub (Jan 28, 2020):
Seems like killing the client process released the port. However it happened to me only once since the last message, so I couldn't verify it. And unfortunately I still cannot find exactly when and why it happens.
@notclive commented on GitHub (Feb 11, 2020):
I recently upgraded a project from WireMock.Net 1.0.37 to 1.1.7 and tests have started failing randomly with:
In the tests, ports are being allocated dynamically by WireMock.
@notclive commented on GitHub (Feb 12, 2020):
After downgrading we're still seeing this, it may have been introduced by an update to .NET Core 3.1 from .NET Core 3.0.
@StefH commented on GitHub (Feb 12, 2020):
Do you use Linux or Windows?
@StefH commented on GitHub (Feb 13, 2020):
https://github.com/WireMock-Net/WireMock.Net/pull/417
@StefH commented on GitHub (Feb 13, 2020):
@notclive I've update the code, can you test MyGet preview version :
WireMock.Net.1.1.7-ci-12712.nupkg?@notclive commented on GitHub (Feb 13, 2020):
These failures are happening on Linux, specifically Docker image
mcr.microsoft.com/dotnet/core/sdk:3.1. I'll try out that package today.@StefH commented on GitHub (Feb 23, 2020):
Hello @notclive did you have time to check this?
@StefH commented on GitHub (Mar 5, 2020):
@notclive Did you have time to check that new Linux Image?
(Note that my linux image does not yet use sdk3.1, but still 2,x)
@StefH commented on GitHub (Mar 13, 2020):
@notclive Did you have time to verify that new linux image.
@notclive commented on GitHub (Apr 13, 2020):
I tried and failed to verify the new build. I set the WireMock.Net version to 1.1.7-ci-12712, but I later discovered I was actually building with 1.1.7.
... depends on WireMock.Net (>= 1.1.7-ci-12712) but WireMock.Net 1.1.7-ci-12712 was not found. An approximate best match of WireMock.Net 1.1.7 was resolved.I now understand that the CI builds are on MyGet not NuGet.
The funny thing is that I didn't see any failures using 1.1.7, I can no longer reproduce the original problem.
Is there still any value in my verifying the new build? I can verify whether it works for me, but I can't verify that it fixes the problem. If so I'll work out how to fetch dependencies from MyGet instead of NuGet.
@StefH commented on GitHub (Apr 13, 2020):
Hello @notclive , Thank you for spending time to test this.
How to use MyGet builds is described here:
https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Please review that wiki-page, and tell me if something could be described different or more clearer if you see it.
But
If you want to just test the WireMock Linux docker image, that's not 100% possible because I don't have a .net core 3.1 version from WireMock.
But if you are just running your own code in a Linux container, that should be possible to re-test
@notclive commented on GitHub (Apr 13, 2020):
It looks like build 1.1.7-ci-12712 no longer exists on MyGet.
@StefH commented on GitHub (Apr 13, 2020):
OK. There is indeed a limit defined.
Just try official latest then.
@notclive commented on GitHub (Apr 13, 2020):
My project's tests, running on Docker image
mcr.microsoft.com/dotnet/core/sdk:3.1, are consistently passing using WireMock.Net 1.2.4.Like I say I can't confirm that the port issue is fixed as I can no longer reproduce the issue, updating to .net core 3.1 probably wasn't the actual cause.
Thanks for all your work.
@StefH commented on GitHub (Apr 13, 2020):
OK. I'll close this issue now. In case you still encounter a problem, just raise a new one.