Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Ladon initialization thread-safe #165

Open
lucarin91 opened this issue Apr 9, 2024 · 0 comments
Open

Make Ladon initialization thread-safe #165

lucarin91 opened this issue Apr 9, 2024 · 0 comments

Comments

@lucarin91
Copy link
Contributor

lucarin91 commented Apr 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant