Possible segment ref data loss in the zipkin receiver plugin
Please answer these questions before submitting your issue.
- Why do you submit this issue? Bug
Bug
-
Which version of SkyWalking, OS and JRE? JRE
-
Which company or project? School research project
-
What happen? If possible, provide a way for reproducing the error. e.g. demo application, component version.
In the code of SegmentBuilder.java in the initSpan function, there is a piece of code which is listed below.
switch (kind) {
case CLIENT:
spanBuilder.setSpanType(SpanType.Exit);
String peer = getPeer(parentSpan, span);
if (peer != null) {
spanBuilder.setPeer(peer);
}
clientSideSpan = new ClientSideSpan(span, spanBuilder);
clientPartSpan.put(span.id(), clientSideSpan);
break;
case SERVER:
spanBuilder.setSpanType(SpanType.Entry);
this.buildRef(spanBuilder, span, parentSegmentSpan, parentSpan);
break;
Notice that clientPartSpan.put(span.id(), clientSideSpan); will set the client span in cache so that when server span arrived, it will fetch client span and build the segment reference.
However, the spans' arriving order is totally random. We can not gurantee that client span will arrive before server span. If server span arrives before client span, the segement ref building process will fail.
This happens several time in my local environment.
Read #2653