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 ResultIteration refuse unsafe operation (option 1) #86

Closed
wants to merge 3 commits into from

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Jan 21, 2021

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

Previously this could panic anyway (see #85), but only when the nodes in an index line up in a very specify way. This meant that tests may not exercise the bug, and the panic would get into a release.

By adding an explicit panic here we ensure that any basic test coverage of an iteration with modification will fail.

In the case of inserts it would not panic, but could return incorrect results (most likely duplicate). This panic ensures we fail instead of returning incorrect results.

It would have been nice to error instead of panic, but there's no place in the current interface to return an error.

TODO:

  • write another test that covers the unsafe usage that previously did not panic, but now does panic
  • apply the same change to the reverse iterator

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.
Previously this could panic anyway (see #85),
but only when the nodse in an index line up in a very specify way. This
meant that tests may not exercise the bug, and the panic would get into
a release.

By adding an explicit panic here we ensure that any basic test coverage
of an iteration would fail.

In the case of inserts it would not panic, but could return incorrect
results (most likely duplicate). This panic ensures we fail instead of
returning incorrect results.

It would have been nice to error instead of panic, but there's no place
in the current interface to return an error.
@@ -6,3 +6,5 @@ require (
github.com/hashicorp/go-immutable-radix v1.3.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
)

replace github.com/hashicorp/go-immutable-radix => github.com/hashicorp/go-immutable-radix v1.3.1-0.20210121185740-67e10d480dcf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving a note as a reminder that this should be changed to an official release, before merging this PR, if we are interested in this approach.

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