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

Fix two race conditions (and possibly go routine leaks) in commands #4406

Merged
merged 2 commits into from
Nov 21, 2017

Conversation

Stebalien
Copy link
Member

fixes #4405

(segfault)

Also, buffer the response channel. I believe we had a go routine leak here
before.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
I believe this also fixes a potential go routine leak (on race).

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
Copy link
Contributor

@keks keks left a 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
}
Copy link
Contributor

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!

Copy link
Member Author

@Stebalien Stebalien Nov 21, 2017

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("😎")}

Copy link
Member

@Kubuxu Kubuxu Nov 21, 2017

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()

@whyrusleeping whyrusleeping merged commit e0f38fa into master Nov 21, 2017
@ghost ghost removed the status/in-progress In progress label Nov 21, 2017
@whyrusleeping whyrusleeping deleted the fix/4405 branch November 21, 2017 23:23
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.

Remove concurrent uses of go-ipfs-cmds.ResponseEmitter
4 participants