Failed to create the imposter with port 4555 and protocol http.

If you’ve ever had the following error when running tests using MbDotNet  / mountebank it can be quite frustrating.

{
    "errors": [
        {
            "code": "resource conflict",
            "message": "Port 4555 is already in use"
        }
    ]
}

It probably means something has not bee disposed of properly when a test has failed i.e. the imposters or the process running mountebank or perhaps you have tests running in parallel *.

Until you work out the cause it can be an annoying thing to try to resolve. How do you know what is using that port / how to free it up?

PowerShell to the rescue. Run the following to find processes running on port 4555.

netstat -ano | Select-String "4555"

Which will give you a result something like:

TCP 0.0.0.0:4555 0.0.0.0:0 LISTENING 26720
TCP [::]:4555 [::]:0 LISTENING 26720

Now to free up the port run:

$id = "26720"
Stop-Process $id

* If the problem causing this is tests running in parallel and you’re using XUnit you may need to add a Properties.cs file with the following content:

using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = true)]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s