rafaeljusto / dnsdisco

DNS service discovery library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default algorithms wrongly sharing states

rafaeljusto opened this issue · comments

When different Discover types are initialized with the default algorithms we could get strange results if one of the algorithms store states inside it. This is currently a problem with the default balancer, that stores the SRV records.

One solution could be copying the default variable when initializing a new Discovery type.

Copying an interface isn't a good idea. For now we have two solutions:

  • Add a Copy method in the interface, that would be called in the Discovery constructor
  • Make the default algorithms private and add constructors that return new copies of them each time they are called

Downside of a new Copy method in the interface is that is one more think that the library's user need to implement if he wants to change a default algorithm. Now making the default algorithms private will move away from the http.DefaultClient standard library model.

The difference between the DefaultLoadBalancer and the http.DefaultClient is that the DefaultLoadBalancer stores internal states where the http.DefaultClient only stores global configurations.

The worst of it is that we can have race conditions. As the locks are in each Discovery type, the ChangeServers method could be accessed at the same time by two or more go routines.