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

Make Insert/Delete refuse unsafe operation (option 3) #88

Closed
wants to merge 3 commits into from

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Jan 22, 2021

This is one option for making the code behave correctly in the scenario described in #85 (other options in #86, #87).

Instead of a panic, make any mutation operation (Insert, Delete*) report an error if there are any iterations that have not been exhausted. This unfortunately requires a change to the interface in the rare case where an iterator is not exhausted in a for loop.

TODO:

  • look for other important test cases

We receicently had [a panic in Consul](hashicorp/consul#9566)
that was caused by incorrect usage of a ResultIterator. A minimal
reproduction of this panic can be seen [here](https://github.com/hashicorp/go-memdb/compare/panic-delete-inside-iter).

Many of us learned that there are undocumented rules for using a
ResultIterator correct with a write transaction.

This commit attempts to document that safe use of a ResultIterator.

func (txn *Txn) checkActiveIterator() error {
if txn.activeIterators > 0 {
return fmt.Errorf("operation is not safe from within a ResultIteration.Next loop")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this error message can be improved, but I'll wait to see what others thing about this option.

@dnephin dnephin closed this in #87 Jan 28, 2021
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.

1 participant