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

Add thread-safe multi error implementation #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

matej-g
Copy link

@matej-g matej-g commented Oct 7, 2022

This is directly inspired by @fpetkovski's work in thanos-io/thanos#5420 (comment).

This PR adds a thread-safe implementation of the NilOrMultiError called NilOrMultiSyncError. PR provides tests as well.

Another small fix in this PR is to unify the method receivers NilOrMultiError to use pointers.

Signed-off-by: Matej Gera <matejgera@gmail.com>
Signed-off-by: Matej Gera <matejgera@gmail.com>
Signed-off-by: Matej Gera <matejgera@gmail.com>
Signed-off-by: Matej Gera <matejgera@gmail.com>
Copy link
Collaborator

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I remember commenting about upstreaming! 🚀

Comment on lines +77 to +79
testutil.NotOk(t, func() error {
return e.Err()
}())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, can't this be

Suggested change
testutil.NotOk(t, func() error {
return e.Err()
}())
testutil.NotOk(t, e.Err())

Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

What about moving to concurrency safe impl only?

@@ -19,12 +19,11 @@
//
// Example 3:
//
// func CloseAll(closers []io.Closer) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right indent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// NilOrMultiSyncError is a thread-safe implementation of NilOrMultiError.
// It allows combining multiple errors into one.
type NilOrMultiSyncError struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we don't want to make the normal implementation concurrency safe 🤔 I don't think it introduces worth noting overhead... The only risk is when somebody would like to have different synchronization techniques that works for them, then they would need to reimplement all.. but sounds like rare use case.

Otherwise another option is to have different package..

I think for me it would make more sense to have ONLY gorotoutine safe implementation here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it depends on what use cases there are out in the wild, but I'd agree having one implementation and documenting that it's concurrency safe so it's clear for the users is the way to go. I'll prepare the changes.

@bwplotka
Copy link
Contributor

I would vote for having just concurrency safe code for merrors. The reason is that soon (Go 1.20) we will likely have errors.Join in standard library, so simple cases will be solved. I don't see a huge overhead of doing concurrency control in seq code when it comes to error handling, but I might underestimate it (:

I would do it (: cc @saswatamcode @matej-g

Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to revisit merror. https://pkg.go.dev/errors@master#Join entered and it might mean we can drop merror completely.

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

Successfully merging this pull request may close these issues.

4 participants