提交 28e686ed 编写于 作者: A ascrutae

1. 修复ExceptionStack过长不截取的问题

2. 修复Netty拆包过程中可能造成数据有问题
上级 489f143f
......@@ -192,9 +192,8 @@ public class Span extends SpanData {
try {
buf = new ByteArrayOutputStream();
Throwable causeException = e;
while (causeException != null
&& (causeException.getCause() != null || expMessage
.length() < maxExceptionStackLength)) {
while (expMessage.length() < maxExceptionStackLength && causeException != null
&& causeException.getCause() != null) {
causeException.printStackTrace(new java.io.PrintWriter(buf,
true));
expMessage.append(buf.toString());
......@@ -209,7 +208,13 @@ public class Span extends SpanData {
"Close exception stack input stream failed", ioe);
}
}
this.exceptionStack = expMessage.toString();
int sublength = maxExceptionStackLength;
if (maxExceptionStackLength > expMessage.length()){
sublength = expMessage.length();
}
this.exceptionStack = expMessage.toString().substring(0, sublength);
if (!exclusiveExceptionSet.contains(e.getClass().getName())) {
this.statusCode = 1;
......
package com.ai.cloud.skywalking.reciever;
import com.ai.cloud.skywalking.reciever.buffer.DataBufferThreadContainer;
import com.ai.cloud.skywalking.reciever.conf.Config;
import com.ai.cloud.skywalking.reciever.conf.ConfigInitializer;
import com.ai.cloud.skywalking.reciever.handler.CollectionServerDataHandler;
import com.ai.cloud.skywalking.reciever.persistance.PersistenceThreadLauncher;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
......@@ -14,18 +15,11 @@ import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import java.io.IOException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.ai.cloud.skywalking.reciever.buffer.DataBufferThreadContainer;
import com.ai.cloud.skywalking.reciever.conf.Config;
import com.ai.cloud.skywalking.reciever.conf.ConfigInitializer;
import com.ai.cloud.skywalking.reciever.handler.CollectionServerDataHandler;
import com.ai.cloud.skywalking.reciever.persistance.PersistenceThreadLauncher;
import java.io.IOException;
import java.util.Properties;
public class CollectionServer {
......@@ -49,7 +43,7 @@ public class CollectionServer {
@Override
public void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 0));
p.addLast("frameEncoder", new LengthFieldPrepender(4));
p.addLast("decoder", new ByteArrayDecoder());
p.addLast("encoder", new ByteArrayEncoder());
......
......@@ -12,7 +12,26 @@ public class CollectionServerDataHandler extends SimpleChannelInboundHandler<byt
Thread.currentThread().setName("ServerReceiver");
// 当接受到这条消息的是空,则忽略
if (msg != null && msg.length >= 0 && msg.length < Config.DataPackage.MAX_DATA_PACKAGE) {
DataBufferThreadContainer.getDataBufferThread().saveTemporarily(msg);
int start = 0;
int end;
while (start < msg.length) {
int length = bytesToInt(msg, start);
start = start + 4;
end = start + length;
byte[] dest = new byte[length];
System.arraycopy(msg, start, dest, 0, length);
DataBufferThreadContainer.getDataBufferThread().saveTemporarily(dest);
start = end;
}
}
}
public static int bytesToInt(byte[] ary, int offset) {
int value;
value = (int) ((ary[offset + 3] & 0xFF)
| ((ary[offset + 2] << 8) & 0xFF00)
| ((ary[offset + 1] << 16) & 0xFF0000)
| ((ary[offset] << 24) & 0xFF000000));
return value;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册