You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/03/21 16:15:25 UTC

[GitHub] [servicecomb-java-chassis] wujimin commented on a change in pull request #2305: [SCB-2216]breakpoints testing for fast timeout of execution

wujimin commented on a change in pull request #2305:
URL: https://github.com/apache/servicecomb-java-chassis/pull/2305#discussion_r598302441



##########
File path: core/src/main/java/org/apache/servicecomb/core/Invocation.java
##########
@@ -482,4 +489,50 @@ public boolean isThirdPartyInvocation() {
 
     return future;
   }
+
+  public void ensureInvocationNotTimeout() throws InvocationException {
+    if (operationMeta.getConfig().getNanoInvocationTimeout() > 0 && calculateElapsedTime() >
+        operationMeta.getConfig().getNanoInvocationTimeout()) {
+      throw new InvocationException(REQUEST_TIMEOUT,
+          ExceptionCodes.INVOCATION_TIMEOUT, "Invocation Timeout.");
+    }
+  }
+
+  public long calculateElapsedTime() {
+    return System.nanoTime() - (long) this.getLocalContext(Const.CONTEXT_TIME_CURRENT)
+        + (long) this.getLocalContext(Const.CONTEXT_TIME_ELAPSED);
+  }
+
+  @Override
+  public void mergeContext(Map<String, String> otherContext) {
+    super.mergeContext(otherContext);
+
+    String elapsed = this.getContext(Const.CONTEXT_TIME_ELAPSED);
+    if (StringUtils.isEmpty(elapsed)) {
+      this.addLocalContext(Const.CONTEXT_TIME_ELAPSED, 0L);
+      return;
+    }
+
+    try {
+      this.addLocalContext(Const.CONTEXT_TIME_ELAPSED, Long.parseLong(elapsed));
+    } catch (NumberFormatException e) {
+      LOGGER.error("Not expected number format exception, attacker?");
+      this.addLocalContext(Const.CONTEXT_TIME_ELAPSED, 0L);
+    }
+  }
+
+  private void initCurrentTimeContext() {
+    // make sure time elapsed is not null
+    this.addLocalContext(Const.CONTEXT_TIME_ELAPSED, 0L);
+
+    // not initialized
+    // 1. when first time received request
+    // 2. when first time send request
+    // initialized
+    // 1. send request in the progress processing request
+    if (this.getLocalContext(Const.CONTEXT_TIME_CURRENT) != null) {

Review comment:
       org.apache.servicecomb.core.invocation.InvocationStageTrace#start  
   try this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org