Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop internalized random number generators in favor of math/rand/v2 #691

Merged
merged 1 commit into from
Dec 14, 2024

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Dec 12, 2024

The service archetype and a number of functions internalized a random
source because in Go, that used to be the only way that you could
guarantee that a non-crypto generated was actually seeded.

Go 1.22 introduced math/rand/v2 which fixed that problem. Now that Go
1.21 support's been dropped, it's a nice clean up to move to the V2
package and get rid of random sources being passed around everywhere.

@brandur brandur requested a review from bgentry December 12, 2024 04:23
// `rand.Rand` argument.
func DurationBetween(rand *mathrand.Rand, lowerLimit, upperLimit time.Duration) time.Duration {
return time.Duration(IntBetween(rand, int(lowerLimit), int(upperLimit)))
func DurationBetween(lowerLimit, upperLimit time.Duration) time.Duration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

riverpro will need a bump to correspond with these internal API changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll send one over.

The service archetype and a number of functions internalized a random
source because in Go, that used to be the only way that you could
guarantee that a non-crypto generated was actually seeded.

Go 1.22 introduced `math/rand/v2` which fixed that problem. Now that Go
1.21 support's been dropped, it's a nice clean up to move to the V2
package and get rid of random sources being passed around everywhere.
@brandur
Copy link
Contributor Author

brandur commented Dec 14, 2024

Also added a changelog just because use of math/rand/v2 might be kind of breaking even if the go.mod has read 1.22 for a while in case code was being vendored in or something.

@brandur brandur merged commit 0ea91f8 into master Dec 14, 2024
10 checks passed
@brandur brandur deleted the brandur-drop-rand branch December 14, 2024 21:06
brandur added a commit that referenced this pull request Dec 14, 2024
Just an incremental release with a couple small changes in #690 and #691.
brandur added a commit that referenced this pull request Dec 14, 2024
Just an incremental release with a couple small changes in #690 and #691.

[skip ci]
@brandur brandur mentioned this pull request Dec 14, 2024
brandur added a commit that referenced this pull request Dec 15, 2024
Just an incremental release with a couple small changes in #690 and #691.

[skip ci]
@sallam-dev
Copy link

This is breaking the ability to embed RiverUI 0.6.0 since it still accesses baseservice.Archetype.Rand at the query_cacher riverqueue.com/riverui@v0.6.0/internal/querycacher/query_cacher.go line 37

@bgentry
Copy link
Contributor

bgentry commented Dec 16, 2024

@sallam-dev sorry about that, fix & new release for riverui coming shortly!

brandur added a commit to riverqueue/riverui that referenced this pull request Dec 16, 2024
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
@brandur
Copy link
Contributor Author

brandur commented Dec 16, 2024

@sallam-dev Just so I understand the breakage correctly ... River UI is still pointed to v0.14.2. Are you saying that the same app is pointing to both River and River UI, thereby getting upgraded to v0.14.3, and thus the breakage?

brandur added a commit to riverqueue/riverui that referenced this pull request Dec 16, 2024
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
@sallam-dev
Copy link

sallam-dev commented Dec 16, 2024

Exactly..

Our usecase involves embedding RiverUI while also using River in the same binary

When upgrading River itself, the shared package got upgraded as well and I had to downgrade back to 0.14.2 to compile the project.

brandur added a commit to riverqueue/riverui that referenced this pull request Dec 16, 2024
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
@brandur
Copy link
Contributor Author

brandur commented Dec 16, 2024

Okay thanks. It hadn't occurred to me before, but I guess the shared rivershared package does make the project a little more brittle than I would've expected. Any breaking changes to it will necessitate immediate releases on every River project to keep everything working.

brandur added a commit to riverqueue/riverui that referenced this pull request Dec 16, 2024
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
brandur added a commit to riverqueue/riverui that referenced this pull request Dec 16, 2024
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
@brandur
Copy link
Contributor Author

brandur commented Dec 16, 2024

@sallam-dev Okay should be fixed as of riverqueue/riverui v0.7.0.

@sallam-dev
Copy link

Great!

Thanks a ton! 🙏

tigrato pushed a commit to gravitational/river that referenced this pull request Dec 18, 2024
…riverqueue#691)

The service archetype and a number of functions internalized a random
source because in Go, that used to be the only way that you could
guarantee that a non-crypto generated was actually seeded.

Go 1.22 introduced `math/rand/v2` which fixed that problem. Now that Go
1.21 support's been dropped, it's a nice clean up to move to the V2
package and get rid of random sources being passed around everywhere.
tigrato pushed a commit to gravitational/river that referenced this pull request Dec 18, 2024
Just an incremental release with a couple small changes in riverqueue#690 and riverqueue#691.

[skip ci]
brandur added a commit that referenced this pull request Dec 19, 2024
Inverts links on #690 and #691 which currently point to each others pull
requests instead of their own, as reported in [1].

[1] #688 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants