Remove global digestLock serialization in digest password storage schemes#667
Open
vharseko wants to merge 2 commits into
Open
Remove global digestLock serialization in digest password storage schemes#667vharseko wants to merge 2 commits into
vharseko wants to merge 2 commits into
Conversation
…emes
Every digest-based password storage scheme (and the CRAM-MD5 SASL handler)
shared a single MessageDigest instance guarded by synchronized(digestLock).
Schemes are server-wide singletons, so all concurrent bind password
verifications for a given scheme were serialized on one monitor, with the
CPU-bound hashing executed under the lock (JFR: ~19s of blocking per 80s
window at 16 worker threads under concurrent {SSHA} bind load).
Replace the shared instance with ThreadLocal<MessageDigest>. Initialization
still fails fast with InitializationException if the algorithm is
unavailable. Password scrubbing (Arrays.fill in finally) is preserved.
Crypt (the unix crypt(3)/DES implementation behind the {CRYPT} storage
scheme's unix mode) kept all of its mutable working buffers in a single
shared SubCrypt instance guarded by synchronized(digestLock). The scheme is
a server-wide singleton, so all concurrent {CRYPT} password encodings and
verifications serialized on one monitor, with the DES work executed under
the lock.
Replace the shared SubCrypt with a ThreadLocal<SubCrypt>. This also fixes a
pre-existing race: _crypt() returns a reference to the shared _iobuf buffer,
and crypt() converted it to bytes after releasing the lock, so a concurrent
call could overwrite the result while it was being read.
This was referenced Jul 2, 2026
maximthomas
approved these changes
Jul 2, 2026
This was referenced Jul 2, 2026
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.
Summary
Removes another global serialization point on the BIND hot path, found while
profiling after #660: every digest-based password storage scheme shares a
single
MessageDigestinstance guarded bysynchronized (digestLock).Schemes are server-wide singletons, so all concurrent bind password
verifications for a given scheme (e.g. every
{SSHA}bind) serialize on onemonitor — with the CPU-bound hashing executed under the lock. The same
pattern is removed from the CRAM-MD5 SASL handler and from the UNIX
crypt(3)implementation behind the{CRYPT}scheme.Problem
SaltedSHA1PasswordStorageScheme.passwordMatches()(and its siblings) hashthe candidate password inside a global
synchronizedblock:Under concurrent BIND load (packaged server, je backend, 5000 users with
{SSHA}passwords, 200 client connections re-binding as random users viaauthrate), JFRjdk.JavaMonitorEntershows this is the dominant monitorcontention once the access-log queues are out of the way: 949 blocking
events totalling ~19 s per 80 s recording across 16 worker threads, with
individual waits of 10–18 ms. After this change the monitor disappears from
the profile entirely.
Change
Salted{SHA1,SHA256,SHA384,SHA512,MD5},SHA1,MD5,CRAMMD5SASLMechanismHandler): replace the sharedMessageDigest+digestLockwith aThreadLocal<MessageDigest>(
ThreadLocal.withInitial); thesynchronizedwrappers are removed,bodies are otherwise unchanged (including the
Arrays.fillpasswordscrubbing in
finally).initialize*still performs a fail-fastMessageDigest.getInstance()so an unavailable algorithm keeps throwingInitializationExceptionat startup, as before.util/Crypt.java(UNIXcrypt(3)/DES used by the{CRYPT}scheme'sunix mode): the shared
SubCryptworking-buffer state guarded by the samelock becomes a
ThreadLocal<SubCrypt>. This also fixes a pre-existingrace:
_crypt()returns a reference to the shared_iobufbuffer, andcrypt()converted it to bytes after releasing the lock, so aconcurrent call could overwrite the result while it was being read.
Testing
mvn -P precommit -pl opendj-server-legacy verifyfor all affectedscheme test cases +
CRAMMD5SASLMechanismHandlerTestCase+CryptPasswordStorageSchemeTestCase: 357 tests, 0 failures.monitor is gone from JFR/jstack profiles; on an 8-core machine the
operating point is CPU-saturated so throughput is unchanged (+~1%), the
win is removal of the serialization ceiling on wider machines.
Files
opendj-server-legacy/src/main/java/org/opends/server/extensions/Salted{SHA1,SHA256,SHA384,SHA512,MD5}PasswordStorageScheme.javaopendj-server-legacy/src/main/java/org/opends/server/extensions/{SHA1,MD5}PasswordStorageScheme.javaopendj-server-legacy/src/main/java/org/opends/server/extensions/CRAMMD5SASLMechanismHandler.javaopendj-server-legacy/src/main/java/org/opends/server/util/Crypt.java