go-radix
go-radix copied to clipboard
Fix panic when node is deleted while walking
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 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 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.
Actually I found a fix that you might prefer, I'll open a PR.
Done in https://github.com/armon/go-radix/pull/22