Skip to content

Add dnsjava.secure_random_algorithm property to select SecureRandom - #419

Merged
ibauersachs merged 1 commit into
dnsjava:masterfrom
ChrisJr404:secure-random-algorithm-property
Oct 3, 2026
Merged

ibauersachs merged 1 commit into
dnsjava:masterfrom
ChrisJr404:secure-random-algorithm-property

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Closes #368

High-volume deployments see lock contention on the default SecureRandom. This adds a dnsjava.secure_random_algorithm system property that selects the SecureRandom algorithm, following the existing dnsjava.* property convention.

Details:

  • New Utils.secureRandom() helper reads the property and returns a SecureRandom for the configured algorithm.
  • Applied at both call sites named in the issue: NioUdpClient (UDP source port selection) and Header (message ID generation). Header.random is static final, so the property is read at class initialization.
  • Graceful fallback: when the property is unset, empty, or names an unavailable algorithm (NoSuchAlgorithmException), it falls back to a default new SecureRandom(). The change is a no-op when the property is not set, so there is no behavior change by default.
  • Documented the new property in the README properties table.

Testing:

  • Added UtilsTest covering the default (unset), a valid algorithm, and an invalid algorithm (fallback) cases.
  • Builds and tests pass on JDK 21 (--release 8).

Allow selecting the SecureRandom algorithm used for UDP source port
and message ID generation via the dnsjava.secure_random_algorithm
system property. This lets heavy-volume deployments pick an algorithm
that avoids the lock contention of the default SecureRandom.

The property is read through a shared Utils.secureRandom() helper used
by both NioUdpClient and Header. When the property is unset or names an
algorithm that is not available, it falls back to the default
SecureRandom, so behavior is unchanged when the property is not set.
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.95%. Comparing base (bb59924) to head (6575462).

Files with missing lines Patch % Lines
src/main/java/org/xbill/DNS/Utils.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master     #419   +/-   ##
=========================================
  Coverage     66.94%   66.95%           
- Complexity     3095     3098    +3     
=========================================
  Files           198      198           
  Lines         13702    13709    +7     
  Branches       2141     2142    +1     
=========================================
+ Hits           9173     9179    +6     
  Misses         3949     3949           
- Partials        580      581    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Oct 3, 2026

Copy link
Copy Markdown

@ibauersachs ibauersachs added this to the v3.6.6 milestone Oct 3, 2026
@ibauersachs
ibauersachs merged commit 26a8d85 into dnsjava:master Oct 3, 2026
20 checks passed
@ibauersachs

Copy link
Copy Markdown
Member

Thanks!

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.

SecureRandom causes high lock contention in heavy-volume environments

2 participants