From 976ffda33bfb8d29c22f47119a4163204bcf974e Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Fri, 14 Jul 2023 11:00:01 +0800 Subject: [PATCH] Support skip use secure random id (#12724) --- .../java/org/apache/dubbo/remoting/Constants.java | 1 + .../org/apache/dubbo/remoting/exchange/Request.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java index ece265989d..51b42ec185 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java @@ -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"; } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java index d212e51bbd..67df1e73ea 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java @@ -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); }