PostgreSQL: Cache salted password and client key#4043
Open
ThomWright wants to merge 1 commit intolaunchbadge:mainfrom
Open
PostgreSQL: Cache salted password and client key#4043ThomWright wants to merge 1 commit intolaunchbadge:mainfrom
ThomWright wants to merge 1 commit intolaunchbadge:mainfrom
Conversation
Contributor
Author
|
@abonander Sorry to bother, have you had a chance to take a look? |
abonander
requested changes
Feb 7, 2026
Comment on lines
+54
to
+59
| host: options.host.clone(), | ||
| port: options.port, | ||
| socket: options.socket.clone(), | ||
| database: options.database.clone(), | ||
| username: options.username.clone(), | ||
| password: options.password.clone().unwrap_or_default(), |
Collaborator
There was a problem hiding this comment.
You shouldn't need to store any of this. Strictly speaking, only 3 things can change the HMAC result:
- the salt;
- the iteration count;
- the password, which can only be changed through an
&mutreference soPgConnectOptions::set_password()can just wipe the cache directly by overwriting it with a new instance.
Comment on lines
+194
to
+199
| let salted_password = hi( | ||
| options.password.as_deref().unwrap_or_default(), | ||
| &cont.salt, | ||
| cont.iterations, | ||
| ) | ||
| .await?; |
Collaborator
There was a problem hiding this comment.
You could theoretically save extra blocking threads from being spawned to redundantly calculate the same salted_password if you use an async Mutex (or RwLock) and held the lock while calculating the new result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A simple single-entry cache for the salted password and client key.
Please let me know what you'd like to see in terms of tests.
Does your PR solve an issue?
Fixes #4032
Is this a breaking change?
No. The cache is internal.