未验证 提交 d844a525 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Fix OOM by empty stack of exception. (#2931)

* Support bootstrap class enhance and fix OOM by empty stack of exception.

* Agent document update

* Remove a word.

* Fix wrong cause exception search.

* Fix the condition

* Revert bootstrap class loader enhance.

* Remove import.

* no message
上级 fa7a1983
......@@ -88,6 +88,11 @@ public class Config {
* The identify of the instance
*/
public static String INSTANCE_UUID = "";
/**
* How depth the agent goes, when log cause exceptions.
*/
public static int CAUSE_EXCEPTION_DEPTH = 5;
}
public static class Collector {
......
......@@ -19,6 +19,8 @@
package org.apache.skywalking.apm.agent.core.context.util;
import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.CAUSE_EXCEPTION_DEPTH;
/**
* {@link ThrowableTransformer} is responsible for transferring stack trace of throwable.
*/
......@@ -30,10 +32,12 @@ public enum ThrowableTransformer {
public String convert2String(Throwable throwable, final int maxLength) {
final StringBuilder stackMessage = new StringBuilder();
Throwable causeException = throwable;
while (causeException != null) {
int depth = CAUSE_EXCEPTION_DEPTH;
while (causeException != null && depth != 0) {
stackMessage.append(printExceptionInfo(causeException));
boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() {
boolean isLookDeeper = printStackElement(causeException.getStackTrace(), new AppendListener() {
public void append(String value) {
stackMessage.append(value);
}
......@@ -43,11 +47,12 @@ public enum ThrowableTransformer {
}
});
if (overMaxLength) {
if (isLookDeeper) {
break;
}
causeException = throwable.getCause();
causeException = causeException.getCause();
depth--;
}
return stackMessage.toString();
......@@ -58,6 +63,14 @@ public enum ThrowableTransformer {
}
private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) {
if (stackTrace.length == 0) {
/**
* In some cases, people would fill empty stackTrace intentionally.
* This is a quick stop.
*/
return true;
}
for (StackTraceElement traceElement : stackTrace) {
printListener.append("at " + traceElement + LINE_SEPARATOR);
if (printListener.overMaxLength()) {
......
......@@ -18,6 +18,8 @@
package org.apache.skywalking.apm.agent;
import java.lang.instrument.Instrumentation;
import java.util.List;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.NamedElement;
......@@ -34,12 +36,15 @@ import org.apache.skywalking.apm.agent.core.conf.ConfigNotFoundException;
import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.plugin.*;
import java.lang.instrument.Instrumentation;
import java.util.List;
import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext;
import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.apache.skywalking.apm.agent.core.plugin.PluginException;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
import static net.bytebuddy.matcher.ElementMatchers.*;
import static net.bytebuddy.matcher.ElementMatchers.nameContains;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.not;
/**
* The main entrance of sky-walking agent, based on javaagent mechanism.
......@@ -80,14 +85,14 @@ public class SkyWalkingAgent {
new AgentBuilder.Default(byteBuddy)
.ignore(
nameStartsWith("net.bytebuddy.")
.or(nameStartsWith("org.slf4j."))
.or(nameStartsWith("org.apache.logging."))
.or(nameStartsWith("org.groovy."))
.or(nameContains("javassist"))
.or(nameContains(".asm."))
.or(nameStartsWith("sun.reflect"))
.or(allSkyWalkingAgentExcludeToolkit())
.or(ElementMatchers.<TypeDescription>isSynthetic()))
.or(nameStartsWith("org.slf4j."))
.or(nameStartsWith("org.apache.logging."))
.or(nameStartsWith("org.groovy."))
.or(nameContains("javassist"))
.or(nameContains(".asm."))
.or(nameStartsWith("sun.reflect"))
.or(allSkyWalkingAgentExcludeToolkit())
.or(ElementMatchers.<TypeDescription>isSynthetic()))
.type(pluginFinder.buildMatch())
.transform(new Transformer(pluginFinder))
.with(new Listener())
......
......@@ -65,6 +65,7 @@ property key | Description | Default |
`agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem.|Not set|
`agent.active_v2_header`|Active V2 header in default.|`true`|
`agent.instance_uuid` |Instance uuid is the identity of an instance, skywalking treat same instance uuid as one instance.if empty, skywalking agent will generate an 32-bit uuid. |`""`|
`agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|5|
`agent.active_v1_header `|Deactive V1 header in default.|`false`|
`collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`|
`collector.app_and_service_register_check_interval`|application and service registry check interval.|`3`|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册