reactive-consul icon indicating copy to clipboard operation
reactive-consul copied to clipboard

selectConnection gets called before addConnectionProvider in LoadBalancerActor

Open sjoerdmulder opened this issue 7 years ago • 6 comments

Having the example new ServiceBroker and immediately call withService then the selectConnection is called on the LoadBalancerActor before the connection providers are added causing an ServiceUnavailableException exception

Example:

val serviceBroker = ServiceBroker(new URL("http://consul.service.consul:8500"), connectionStrategies)
serviceBroker.withService[String, Unit]("my-service") { value => ... }
```

sjoerdmulder avatar Aug 24 '17 13:08 sjoerdmulder

Hi @sjoerdmulder,

What do you feel would be reasonable behavior? I could either introduce the concept of 'readiness' to the ServiceBroker constructor, having it return a Future[ServiceBroker] or I could build some mechanism into withService that would await the first query of Consul along with the construction of connections. I feel that the latter option would probably be the most user-friendly, agreed?

dlouwers avatar Aug 24 '17 14:08 dlouwers

Yeah, last option is better since it's already returns a Future. Great project BTW! If you need any help or want a PR let me know.

sjoerdmulder avatar Aug 24 '17 14:08 sjoerdmulder

Hi @sjoerdmulder. I am now stashing GetConnection messages until the first consul query has been done. This means that you might still not get a connection if Consul isn't aware of it ofc. Please try the 0.4.0 snapshot.

dlouwers avatar Sep 23 '17 15:09 dlouwers

Cool, i have not yet had time to test will do this hopefully within couple of weeks for you.

sjoerdmulder avatar Oct 03 '17 16:10 sjoerdmulder

Hi @sjoerdmulder. I have given it some thought and have come to the conclusion that this feature has added far more complexity than it solves. In a next release, I will remove this feature in favor of advising people to use a retry mechanism from the outside.

dlouwers avatar Mar 23 '18 16:03 dlouwers

Ok, no problem. The problem is likely not happening in real code since the creation of ServiceBroker happens on startup and after some time when the service is ready / started it will start using the .withService

sjoerdmulder avatar Mar 29 '18 07:03 sjoerdmulder