surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
231 stars 62 forks source link

Bug/id generation #47

Closed plally closed 1 year ago

plally commented 1 year ago

When testing with a large amount of concurrent requests for my previous PR #45 I noticed id collisions were very frequent. I believe this was happening because if 2 ids are generated at the same time they can get the same seed resulting in their IDs being the same. This PR changes the id generation to just set the seed once and use our own random number source instead of the library default.

We need a Mutex here because random sources are not concurrency safe, Internally rand.Read also uses a Mutex.

Another solution could be to just not set the seed every time we generate an ID.

ffrizzo commented 1 year ago

I believe this is fixed here https://github.com/surrealdb/surrealdb.go/pull/36

plally commented 1 year ago

Yeah, I think it would be. I didn't see your PR. Thanks.