RedBlackTree runtime error: index out of range in .Values() func #174
Labels
No labels
bug
discussion
documentation
duplicate
ignore
new feature
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/gms-gods#174
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi
I am using the RedBlackTree. Sometimes, when the application is under heavy traffic, this error shows up:
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 🙏🏻
@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