-
Notifications
You must be signed in to change notification settings - Fork 1
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: updates jwx library to use its thread-safe jwks cache #88
Conversation
795b803
to
8cb184a
Compare
app.go
Outdated
@@ -38,16 +42,17 @@ func New(appID string, config *Config) (*App, error) { | |||
client: client, | |||
} | |||
|
|||
app.JWKS, err = app.fetchJWKS() | |||
if err != nil { | |||
// cached set setup taken from https://github.com/lestrrat-go/jwx/blob/8d1d78351e9f259723f9f558889a78e327379683/examples/jwk_cache_example_test.go#L21-L36 |
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.
This link can perhaps be omitted, as the example is surfaced in the package's docs here.
But I'm also good with keeping it if it feels like a good point of reference.
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.
removed in 058e8d4
287bc9e
to
058e8d4
Compare
Quality Gate passedIssues Measures |
What's New?
Problem:
Our jwks cache was a
map
, so it is not thread safe.If the
passage.App
struct was being called viapassage.New
in multiple threads, i.e. it is being initialized per request thread in an API server, then it would throw a fatal "concurrent map writes" error.Solution:
Use a thread-safe data structure to cache the jwks.
Our existing jwt/jwks library, https://github.com/lestrrat-go/jwx, has its own thread-safe (via RW mutex) caching implementation that we can make use of by upgrading from v1 to v2.
Tests:
Adding and running this test on
main
will fail because it detects a race condition (concurrent writes to thejwkCache
map variable). It will pass on this branchpassage-go/app_test.go
Lines 52 to 70 in 795b803
References:
Screenshots (if appropriate):
Please attach any screenshots that would help illustrate the changes.
Type of change
Checklist:
Additional context
Add any other context or screenshots about the pull request here.