Make Ladon initialization thread-safe
lucarin91 opened this issue · 0 comments
Do you want to request a feature or report a bug?
This is probably a feature request
What is the current behavior?
AFAIK the Ladon struct could be easily considered thread-safe because all its internal fields (e.g., Matcher
, Manager
) handle concurrency internally. Although, the lazy initialization isn't thread-safe. For instance, the metric
function has a data race because multiple callers can concurrently try to initialize the matcher to the DefaultMetric
.
func (l *Ladon) metric() Metric {
if l.Metric == nil {
l.Metric = DefaultMetric
}
return l.Metric
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
What is the expected behavior?
I didn't find any claim that the Ladon
struct is thread-safe, but I think with some small changes we can improve this and make a clear statement that this is safe to use from multiple goroutines.
Here is a possible solution with sync.Once
lucarin91#1 which will keep the same interface. But I think we should consider changing the interface and province a constructor, which will be better and simple
Which version of the software is affected?
I am testing on master 972387f