Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, concurrent calls to
ReverseGeocode
will have undefined results due to iterator reuse between concurrent calls. The devil is in the detail, specifically a comment ons2.ContainsPointQuery
mentions that:The Go race detector does not find this issue by default, because tests are not parallelized. I add a separate commit to parallelize the tests and thus enable detection of the issue via
go test -count=1 -race -run=TestReverseGeocode_Countries
:Solution
The issue can be avoided by simply constructing a new query for every lookup.
Performance evaluation
I found that this change does not impact test runtime, because
ShapeIndex
internally optimizes to build the index only once for the first query in a thread-safe manner. Unchanged timing can be verified viatime go test -count=1 -parallel=1
.However, due to changed timing of
New
and the firstReverseGeocode
call, this merge request should not land in a patch but rather a minor release with appropriate release notes that mention this detail. A newBuild
method is added to exposeShapeIndex.Build
if the user wants to avoid indexing overhead with the first lookup.Best,
Oliver