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

Aquire semaphore when network will be accessed #25

Merged
merged 2 commits into from
Mar 2, 2024
Merged

Aquire semaphore when network will be accessed #25

merged 2 commits into from
Mar 2, 2024

Conversation

natenjoy
Copy link

@natenjoy natenjoy commented Mar 1, 2024

Potential fix for #24 . The full fix required not just acquiring the semaphore in cache.go more guardedly, but also not locking the event in queue.go until after the network request is made.

From a concurrency standpoint, the change to queue.go is safe because:

  • Event as a whole is not much used.
  • Its use is guarded by semaphpore.
  • queue.go still only uses it under mutex, except for the read on e.request

As a sanity check, I ran go test -race -count=1 ./... 100 times against this patch and the race detector did not find issues. The bug reproduction repo (https://github.com/natenjoy/httprc-cache-issue) contains instructions in how to run this patch against a minimal server setup.

I did see there is a v2 branch, but I still opted to open this PR against the main branch since latest tagged jwx package still uses v1.0.4. I was hoping if this change (eventually) looks mergeable that you could pull it over to the v2 branch.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.42%. Comparing base (8a18d6d) to head (2d1b1b4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #25      +/-   ##
==========================================
- Coverage   64.01%   63.42%   -0.59%     
==========================================
  Files           6        6              
  Lines         503      432      -71     
==========================================
- Hits          322      274      -48     
+ Misses        168      145      -23     
  Partials       13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lestrrat
Copy link
Collaborator

lestrrat commented Mar 2, 2024

Ah I see. That makes sense. Thanks, but please wait a few more days for a release: I generally like to take a breathe and let the dust settle before going ahead with releases.

@lestrrat lestrrat merged commit e73952d into lestrrat-go:main Mar 2, 2024
2 checks passed
@natenjoy natenjoy deleted the aquire-sem-on-fetch branch March 4, 2024 14:03
@lestrrat
Copy link
Collaborator

lestrrat commented Mar 6, 2024

mental note: this does not apply to v2, as we do not have a worker pool

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.

None yet

3 participants