Port not released #154

Closed
opened 2025-12-29 14:23:51 +01:00 by adam · 2 comments
Owner

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.
image
which means that I cannot run the test again.

How do I release the port?

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. ![image](https://user-images.githubusercontent.com/7672549/49795240-cb441500-fd39-11e8-9621-c491f1bb0c44.png) which means that I cannot run the test again. How do I release the port?
adam added the question label 2025-12-29 14:23:51 +01:00
adam closed this issue 2025-12-29 14:23:51 +01:00
Author
Owner

@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)

@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)
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#154