Procházet zdrojové kódy

Bug fix for automatic exit of default context when exiting the entry

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao před 6 roky
rodič
revize
cbaacfda55
2 změnil soubory, kde provedl 19 přidání a 2 odebrání
  1. +3
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtEntry.java
  2. +16
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java

+ 3
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/CtEntry.java Zobrazit soubor

@@ -89,8 +89,9 @@ class CtEntry extends Entry {
}
if (parent == null) {
// Default context (auto entered) will be exited automatically.
// Note: NullContext won't be exited automatically.
ContextUtil.exit();
if (ContextUtil.isDefaultContext(context)) {
ContextUtil.exit();
}
}
// Clean the reference of context in current entry to avoid duplicate exit.
clearEntryContext();


+ 16
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/context/ContextUtil.java Zobrazit soubor

@@ -23,6 +23,7 @@ import com.alibaba.csp.sentinel.Constants;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.SphO;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.node.DefaultNode;
import com.alibaba.csp.sentinel.node.EntranceNode;
import com.alibaba.csp.sentinel.node.Node;
@@ -73,6 +74,7 @@ public class ContextUtil {
*/
static void resetContextMap() {
if (contextNameNodeMap != null) {
RecordLog.warn("Context map cleared and reset to initial state");
contextNameNodeMap.clear();
initDefaultContext();
}
@@ -190,6 +192,20 @@ public class ContextUtil {
}
}

/**
* Check if provided context is a default auto-created context.
*
* @param context context to check
* @return true if it is a default context, otherwise false
* @since 0.2.0
*/
public static boolean isDefaultContext(Context context) {
if (context == null) {
return false;
}
return Constants.CONTEXT_DEFAULT_NAME.equals(context.getName());
}

/**
* Get {@link Context} of current thread.
*


Načítá se…
Zrušit
Uložit