-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix two race conditions (and possibly go routine leaks) in commands #4406
Conversation
(segfault) Also, buffer the response channel. I believe we had a go routine leak here before. License: MIT Signed-off-by: Steven Allen <[email protected]>
I believe this also fixes a potential go routine leak (on race). License: MIT Signed-off-by: Steven Allen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
type pinResult struct { | ||
pins []*cid.Cid | ||
err error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I did not know you could define types in functions. Neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to have some real fun?
ch := make(chan struct{pins []*cid.Cid, err error}, 1)
//...
ch <- struct{pins []*cid.Cid, err error}{err: errors.New("😎")}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some other trick for you:
type System struct {
cntrSafe struct {
sync.Mutex
n int
}
mapSafe struct {
sync.Mutex
m map[int]int
}
}
usage
s := &System{}
s.cntrSafe.Lock()
s.cntrSafe.n++
s.cntrSafe.Unlock()
fixes #4405