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 suboptimal lock release in (*handler).getChainInfo. #733

Merged
merged 1 commit into from
Aug 4, 2020
Merged

Fix suboptimal lock release in (*handler).getChainInfo. #733

merged 1 commit into from
Aug 4, 2020

Conversation

gnattishness
Copy link
Contributor

Possible source of bugs in the future but not currently a problem, as h.chainInfo is never set to nil but from nil.

getChainInfo could sometimes unnecessarily return nil if h.chainInfo were set to nil after releasing the h.chainInfoLk read lock.

Also remove direct, unsynchronized access to h.chainInfo in h.getRand(). Similarly not a bug in the current usage, but could be a source of crashes if h.chainInfo is set to nil, or h.getRand() isn't called after a previous call to h.getChainInfo()

Also remove direct access to h.chainInfo.

No race condition currently possible because `h.chainInfo` is never set
to `nil` but, if it were, `getChainInfo` could sometimes unnecessarily return `nil`.

Possible source of bugs in the future.
@@ -212,7 +214,7 @@ func (h *handler) getRand(ctx context.Context, round uint64) ([]byte, error) {
}

// make sure we aren't going to ask for a round that doesn't exist yet.
if time.Unix(chain.TimeOfRound(h.chainInfo.Period, h.chainInfo.GenesisTime, round), 0).After(time.Now()) {
if time.Unix(chain.TimeOfRound(info.Period, info.GenesisTime, round), 0).After(time.Now()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling h.getChainInfo() here is perhaps neater, but requires unnecessary locking.
Passing as a parameter encodes/enforces the current assumption that getRand is only called after a call to h.getChainInfo()

@willscott willscott merged commit 84eedb1 into drand:master Aug 4, 2020
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.

None yet

2 participants