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

Bug in iavlIterator.Close() can cause race condition (store/iavl/store.go) #5276

Closed
4 tasks
wangkui0508 opened this issue Nov 5, 2019 · 2 comments · Fixed by #5279
Closed
4 tasks

Bug in iavlIterator.Close() can cause race condition (store/iavl/store.go) #5276

wangkui0508 opened this issue Nov 5, 2019 · 2 comments · Fixed by #5279

Comments

@wangkui0508
Copy link

Summary of Bug

In store/iavl/store.go, the implementation of "func (iter *iavlIterator) Close()" does not wait iterateRoutine to fully exit. So, after Close() returns, iterateRoutine can still run for a while, which may cause race condition.

Version

v0.37.4

Steps to Reproduce

Hard to reproduce, since it is a race condition. In our not-opensourced-yet project, we occasionally meet this bug.

The following code can fix this bug:

func (iter *iavlIterator) Close() {
	close(iter.quitCh)
	// wait iter.iterCh to close
	for range iter.iterCh {}
}

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez
Copy link
Contributor

alexanderbez commented Nov 5, 2019

Alternatively, can't we send on a "done" channel in iterateRoutine after we call close(iter.iterCh) and then wait on that done channel in Close()?

@wangkui0508
Copy link
Author

Yes, I believe your method can also work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants