go-radix icon indicating copy to clipboard operation
go-radix copied to clipboard

Fix panic when node is deleted while walking

Open thaJeztah opened this issue 3 years ago • 1 comments

carries https://github.com/armon/go-radix/pull/12 closes https://github.com/armon/go-radix/pull/12

relates to https://github.com/moby/libnetwork/pull/2581

thaJeztah avatar Sep 11 '20 15:09 thaJeztah

@thaJeztah It seems like the only way to hit this issue is to be doing concurrent read/write operations without synchronization. This means a delete took place concurrently with a walk. This fix might avoid a particular race condition, but the library itself is not designed for concurrent read/write and there are likely other edge cases that are not handled.

armon avatar Sep 14 '20 21:09 armon

@armon It has nothing to do with multiple goroutines. It's about deleting the tree we're walking. Here is a test repro:

func Test1(t *testing.T) {
	tree := New()
	tree.Insert("foo/bar/k0", "value")
	tree.Insert("foo/bar/k1", "value")
	tree.Walk(func(s string, v interface{}) bool {
		tree.Delete(s)
		return false
	})
}

IMHO, this PR is not unreasonable.

tiborvass avatar Nov 17 '22 17:11 tiborvass

Actually I found a fix that you might prefer, I'll open a PR.

tiborvass avatar Nov 17 '22 17:11 tiborvass

Done in https://github.com/armon/go-radix/pull/22

tiborvass avatar Nov 17 '22 21:11 tiborvass