mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Port not released #154
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 @SabrinaMH on GitHub (Dec 11, 2018).
I'm using WireMock in an NUnit test, where I spin up a server on port 9002. At the end of the test (and in case of exceptions) I make sure to shut down the server using the following lines of code:
server.Stop(); server.Dispose();However, the port is still in use, cf.

which means that I cannot run the test again.
How do I release the port?
@StefH commented on GitHub (Dec 11, 2018):
You cannot release the port manually. It's done by the OS.
This can take some time.
See also https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process
In your case the best is to use a dynamic port in each uni-test (see also my unit-tests in this project)
@SabrinaMH commented on GitHub (Dec 11, 2018):
Thanks for the reply!
I actually thought that the app needed to put the socket into TIME_WAIT in order for the OS to be able to know that it is not User anymore.