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

Use proper read lock for FieldTrie #8588

Merged
merged 2 commits into from
Mar 10, 2021
Merged

Use proper read lock for FieldTrie #8588

merged 2 commits into from
Mar 10, 2021

Conversation

terencechain
Copy link
Member

In FieldReferencesCount(), we call f.Refs() which uses the reference lock

Then it calls len(f.fieldLayers) which uses the reference lock again. Instead it should be using FieldTrie lock.

// FieldTrie is the representation of the representative trie of the particular field.
type FieldTrie struct {
	*sync.RWMutex // <- We should use this lock
	*reference
	fieldLayers [][]*[32]byte // <- When reading this
	field       fieldIndex
}

type reference struct {
	refs uint
	lock sync.RWMutex // <- We SHOULD NOT use this lock
}

Note that I changed FieldTrie's lock to RWMutex to gain read locking

@terencechain terencechain requested a review from a team as a code owner March 10, 2021 21:39
@terencechain terencechain self-assigned this Mar 10, 2021
@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

❗ No coverage uploaded for pull request base (develop@548b471). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             develop    #8588   +/-   ##
==========================================
  Coverage           ?   58.63%           
==========================================
  Files              ?      457           
  Lines              ?    32845           
  Branches           ?        0           
==========================================
  Hits               ?    19260           
  Misses             ?    10667           
  Partials           ?     2918           

@terencechain terencechain merged commit dc0fc94 into develop Mar 10, 2021
@delete-merged-branch delete-merged-branch bot deleted the right-lock branch March 10, 2021 23:11
Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

Nice Catch !

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.

3 participants