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

fix duplicate key deletion when forget called #14

Merged
merged 2 commits into from
Sep 3, 2024
Merged

Conversation

cyolosec
Copy link
Contributor

@cyolosec cyolosec commented Sep 3, 2024

Hey @janos,

I believe your implementation of singleflight is affected by the issue described here:
golang/go#31420.

This issue specifically impacts your implementation because a thread can call Forget() after its own context has expired.
I implemented the solution found in this CL:
https://go-review.googlesource.com/c/sync/+/171897.

All existing tests pass successfully, and I also added the test from the CL to ensure that the new behavior is consistent with Google’s implementation.

Note: Before applying the fix, the TestForgetMisbehaving test failed.

Copy link
Owner

@janos janos left a comment

Choose a reason for hiding this comment

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

Hi, @cyolosec. Thank you for porting this fix. There is only one linter warning that should be handled.

secondCh := make(chan struct{})
secondRunning := make(chan struct{})
go func() {
g.Do(context.Background(), "key", func(ctx context.Context) (i int, e error) {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you explicitly check or ignore the error from g.Do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ofc, done :-)

@cyolosec cyolosec requested a review from janos September 3, 2024 15:10
Copy link
Owner

@janos janos left a comment

Choose a reason for hiding this comment

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

Thank you very much for contributing this patch.

@janos janos merged commit 10a8876 into janos:master Sep 3, 2024
3 checks passed
@cyolosec
Copy link
Contributor Author

cyolosec commented Sep 3, 2024

hey @janos thanks for merging,
when can we expect to see a release?

@janos
Copy link
Owner

janos commented Sep 3, 2024

Ah yes, version 0.4.3 has been released just now.

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.

2 participants