-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(random): use crypto/rand for random string generator #55
Conversation
maybe https://github.com/labstack/echo/blob/e6b96f8873fed46e71e0d34cddb81c533167f954/middleware/util.go#L69 would be suitable here also. |
Thank you for the comment. I will take a look the link you mentioned and update the PR accordingly. |
@aldas I have updated the source code as you suggested. Please let me know what you think. |
This reverts commit 213dc71.
@aldas Hi, just wondering what is the progress for this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The current implementation for
random
package relied on globally seeded value.If any other part of the programs call
rand.Seed
, the string generate byrandom
package will also be affected.To fix this issue, instead of callingrand.Seed
during initialization,NewSource
is called and the return value is stored insideRandom
struct.I made changes by referring to the source code from the link below.
https://github.com/labstack/echo/blob/e6b96f8873fed46e71e0d34cddb81c533167f954/middleware/util.go#L69
I also did some benchmarks before and after the update.
Before
After (with sync.Mutex)
After (with sync.Pool)