ASP.NET Core with http.sys: Registration still in use when restarting application quickly

I have multiple ASP.NET Core 3.1 programs using http.sys being started by a single process running as a windows service. The service puts all processes in the same job to make sure that if it should die all processes are terminated as well.

This works perfectly fine, except sometimes when restarting the service I get the following error during startup:

[Error] [Microsoft.AspNetCore.Server.HttpSys.HttpSysListener] Start
Microsoft.AspNetCore.Server.HttpSys.HttpSysException (183): The prefix 'http://+:31955/' is already registered.
   at Microsoft.AspNetCore.Server.HttpSys.UrlGroup.RegisterPrefix(String uriPrefix, Int32 contextId)
   at Microsoft.AspNetCore.Server.HttpSys.UrlPrefixCollection.RegisterAllPrefixes(UrlGroup urlGroup)
   at Microsoft.AspNetCore.Server.HttpSys.HttpSysListener.Start()

Waiting a few seconds and then starting the service again allows the processes to start without problems every time. My assumption therefore is that there is a race condition between http.sys freeing the url registration from the killed process and giving it to the new one.

What is the best way to avoid such a problem?



from Recent Questions - Stack Overflow https://ift.tt/2Mg22yc
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations