-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: only lock for key generation #3866
Conversation
I doubt this adds anything valuable but just in case, here's a couple ideas:
awill1988@b645b23#diff-cf3d2851cb06a9dfce1d62248d47c33494589220b8c2cca64c576a5d45b42594L167 |
|
@terev for 2. the thought was by putting behind a db trx I imagined it could block if there's an insert happening on the table but that's making some broad assumptions about the level of trx isolation per db implementation and likely not the right solution. I think @alnr had mentioned something along the lines of selecting for insert.. maybe putting the whole function in a db transaction would work? |
Atomic maps are also just maps with a sync mutex. Unfortunately |
@awill1988 I'm not 100% sure but I think trying to accomplish this in a single transaction will result in deadlocks. At least for the default isolation level. The sync.Map is more sophisticated than just a map protected by a mutex. But since reading from the map isn't on the hot path it seems reasonable to just use a mutex. I noticed we're not using the read lock when accessing the map so maybe we just use a plain mutex? |
He did, but doing INSERT ON CONFLICT on every JWK read is (I would assume) significantly more expensive than just reading from a read only transaction, as we have to acquire (potentially) a write lock. I really don't think this is a good solution as this functino is being quite a lot (which is why we're getting lock contention in the first place). |
I'm not suggesting an insert on every read. Just when the select returns no rows. |
Hm, not sure why conformity tests are failing. Maybe we generate too many keys now and it confuses the tests. |
Closes #3865
Closes #3863
Related issue(s)
Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
[email protected]) from the maintainers to push
the changes.
works.
Further Comments