You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/12/27 12:09:13 UTC

[dubbo] branch 3.0 updated: [3.0] Fix timeout cal in Profiler exceed int range (#9503)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 32a083c  [3.0] Fix timeout cal in Profiler exceed int range (#9503)
32a083c is described below

commit 32a083cfc3db833b460bc0e406b3e086f07ea479
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Mon Dec 27 20:09:02 2021 +0800

    [3.0] Fix timeout cal in Profiler exceed int range (#9503)
---
 .../main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java | 6 +++---
 .../java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java   | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java
index c8ad2ed..553c30a 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java
@@ -76,14 +76,14 @@ public class ProfilerServerFilter implements Filter, BaseFilter.Listener {
 
     private void dumpIfNeed(Invoker<?> invoker, Invocation invocation, ProfilerEntry profiler) {
         int timeout;
-        Object timeoutKey = invocation.getObjectAttachment(TIMEOUT_KEY);
+        Object timeoutKey = invocation.getObjectAttachmentWithoutConvert(TIMEOUT_KEY);
         if (timeoutKey instanceof Integer) {
             timeout = (Integer) timeoutKey;
         } else {
-            timeout = invoker.getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
+            timeout = invoker.getUrl().getMethodPositiveParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT);
         }
         long usage = profiler.getEndTime() - profiler.getStartTime();
-        if (usage > (timeout * 1000_000 * ProfilerSwitch.getWarnPercent())) {
+        if ((usage / (1000_000L * ProfilerSwitch.getWarnPercent())) > timeout) {
 
             StringBuilder attachment = new StringBuilder();
             for (Map.Entry<String, Object> entry : invocation.getObjectAttachments().entrySet()) {
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
index 1b440b5..8af03a3 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
@@ -101,14 +101,14 @@ public class InvokerInvocationHandler implements InvocationHandler {
                 Profiler.release(bizProfiler);
                 if (!containsBizProfiler) {
                     int timeout;
-                    Object timeoutKey = rpcInvocation.getObjectAttachment(TIMEOUT_KEY);
+                    Object timeoutKey = rpcInvocation.getObjectAttachmentWithoutConvert(TIMEOUT_KEY);
                     if (timeoutKey instanceof Integer) {
                         timeout = (Integer) timeoutKey;
                     } else {
-                        timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
+                        timeout = url.getMethodPositiveParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT);
                     }
                     long usage = bizProfiler.getEndTime() - bizProfiler.getStartTime();
-                    if (usage > (timeout * 1000_000 * ProfilerSwitch.getWarnPercent())) {
+                    if ((usage / (1000_000L * ProfilerSwitch.getWarnPercent())) > timeout) {
                         StringBuilder attachment = new StringBuilder();
                         for (Map.Entry<String, Object> entry : rpcInvocation.getObjectAttachments().entrySet()) {
                             attachment.append(entry.getKey()).append("=").append(entry.getValue()).append(";\n");