RedBlackTree runtime error: index out of range in .Values() func #174

Closed
opened 2021-10-15 08:04:47 +00:00 by shojaeix · 1 comment
shojaeix commented 2021-10-15 08:04:47 +00:00 (Migrated from github.com)

Hi

I am using the RedBlackTree. Sometimes, when the application is under heavy traffic, this error shows up:

panic: runtime error: index out of range [2477] with length 2477

goroutine 83 [running]:
github.com/emirpasic/gods/trees/redblacktree.(*Tree).Values(0xc000004210, 0x2030099, 0x2030099, 0x20)
        C:/Users/Nitro-5/go/pkg/mod/github.com/emirpasic/[email protected]/trees/redblacktree/redblacktree.go:173 +0x10f

First, I thought maybe it's not thread-safe, So I started to use an RWmutex for the tree, but still facing the error.

Thanks for your help 🙏🏻

Hi I am using the RedBlackTree. Sometimes, when the application is under heavy traffic, this error shows up: ``` panic: runtime error: index out of range [2477] with length 2477 goroutine 83 [running]: github.com/emirpasic/gods/trees/redblacktree.(*Tree).Values(0xc000004210, 0x2030099, 0x2030099, 0x20) C:/Users/Nitro-5/go/pkg/mod/github.com/emirpasic/[email protected]/trees/redblacktree/redblacktree.go:173 +0x10f ``` First, I thought maybe it's not thread-safe, So I started to use an RWmutex for the tree, but still facing the error. Thanks for your help 🙏🏻
emirpasic commented 2021-10-15 09:48:01 +00:00 (Migrated from github.com)

@shojaeix

GoDS is not thread-safe (seeing this error, I am now having second thoughts make it all thread-safe), so protecting access to it is crucial with mutexes as you have done, otherwise, we could run into an undefined state.

The error occurs in the Values() function, so I guess that the tree is in an inconsistent state due to concurrent reads and writes. Try using a common mutex for both reading and writing on the tree, even when calling the Values() as something might be concurrently writing/deleting to the tree and the size of the tree in this function is not correct at that moment.

Let me know if this helps

@shojaeix GoDS is not thread-safe (seeing this error, I am now having second thoughts make it all thread-safe), so protecting access to it is crucial with mutexes as you have done, otherwise, we could run into an undefined state. The error occurs in the Values() function, so I guess that the tree is in an inconsistent state due to concurrent reads and writes. **Try using a common mutex for both reading and writing on the tree, even when calling the Values()** as something might be concurrently writing/deleting to the tree and the size of the tree in this function is not correct at that moment. Let me know if this helps
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#174
No description provided.