Support skip use secure random id (#12724)

This commit is contained in:
Albumen Kevin 2023-07-14 11:00:01 +08:00 committed by GitHub
parent 65491fda07
commit 976ffda33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -173,4 +173,5 @@ public interface Constants {
String CONTENT_LENGTH_KEY = "content-length";
String USE_SECURE_RANDOM_ID = "dubbo.application.use-secure-random-request-id";
}

View File

@ -23,6 +23,7 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
import static org.apache.dubbo.remoting.Constants.USE_SECURE_RANDOM_ID;
/**
* Request.
@ -55,10 +56,12 @@ public class Request {
static {
long startID = ThreadLocalRandom.current().nextLong();
try {
SecureRandom rand = new SecureRandom(SecureRandom.getSeed(20));
startID = rand.nextLong();
} catch (Throwable ignore) {
if (Boolean.parseBoolean(System.getProperty(USE_SECURE_RANDOM_ID, "true"))) {
try {
SecureRandom rand = new SecureRandom(SecureRandom.getSeed(20));
startID = rand.nextLong();
} catch (Throwable ignore) {
}
}
INVOKE_ID = new AtomicLong(startID);
}