dhconnelly / rtreego

an R-Tree library for Go

Home Page:http://dhconnelly.github.com/rtreego

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrent Splits Crash With Duplicate Inserts

200sc opened this issue · comments

I've been working with (a fork of) Patrick Higgins' fork of this package, but this same code exists in all three forks so I figured I should make note of this crash I've been seeing.

When inserting several Spatials at the same time at the same location and dimensions, this piece of code can break, as split tries to use indices to split with that are no longer valid, as it reset the entries in n.


func (n *node) split(minGroupSize int) (left, right *node) {
	// find the initial split
	l, r := n.pickSeeds()

	leftSeed, rightSeed := n.entries[l], n.entries[r]  <---- Crash here, index out of range, 2nd goroutine

	// get the entries to be divided between left and right
	remaining := append(n.entries[:l], n.entries[l+1:r]...)
	remaining = append(remaining, n.entries[r+1:]...)

	// setup the new split nodes, but re-use n as the left node
	left = n
	left.entries = []entry{leftSeed} <----- reset n's entries here, 1st goroutine
        ...

This can also show up sooner, here, when pickSeeds tries to range over entries[i+1:].

I don't think this is worth fixing, but I figured it was worth documenting. I just changed how the calling code worked so it wouldn't add duplicates.

Interesting. Thanks for writing this up!