Consul multiple registration


If you use Consul for service discovery, the services will register with a different id each time they are started.
If you do multiple deployments, you’ll end up with tens (or more) registrations for the same service.
Is there a way to prevent this? Is it on Consul’s side to investigate?


Hi, what’s the actual issue that you’re trying to resolve? Once the service is down it will be automatically removed from Consul. Each service will have it’s unique id (that you can easily override, as we use Guid here, but the id generation strategy can me more sophisticated) and will be grouped as instance 1…N based on the service name (e.g. orders-service) which is the desired result.


The service is removed from Consul if it’s down for a certain period of time.
During deployments, the service is down for several seconds, less than 10 seconds (in my case), which is not enough for Consul.

And Consul will ping the same instance, by IP, multiple times, for each registration.
And it will keep the multiple registrations.

So maybe Consul (or the client side code) should make sure it’s not keeping multiple registrations for the same IP.


I see, at first you could modify the ping interval (lesser number), however, if you take a look at the Startup class, you can see there, that the application automatically removes itself from Consul (Deregister()) as long as there was a graceful shutdown.


Yes, I noticed that code, however it never worked.
Or, the app was not properly shut down.

I’ll investigate further.


We will check, should work, but might be that there’s some issue.


I added some logging to be displayed during registration and de-registration, and the service is indeed removed from Consul when I press CTRL+C in console.

applicationLifetime.ApplicationStopped.Register(() => 
        Log.Logger.Information($"Unregistering service {consulServiceId} from Consul.");

But also I’m getting this error:
watch : Exited with error code -1073741510

Anyway, the good thing is that the instance is removing itself from Consul.


Ok, we will need to check what’s the error about :).