cpp2sky icon indicating copy to clipboard operation
cpp2sky copied to clipboard

sendSegment is not thread-safe

Open liberize opened this issue 4 years ago • 5 comments

sendSegment is not thread-safe because GrpcAsyncSegmentReporterStream::clearPendingMessages is not which causes SIGABRT with proto_buffer_writer.h:65 assertion failed: !byte_buffer->Valid()

liberize avatar Dec 21 '20 09:12 liberize

@Shikugawa Do we open multiple threads for sending the segment?

wu-sheng avatar Dec 21 '20 09:12 wu-sheng

It won't be a problem on Envoy integration so I ignored this problem although I already know about it. But when we use it as SDK, It will be a critical problem. This problem is not directly related with Envoy integration. So I will submit a patch for 0.2.0.

Shikugawa avatar Dec 21 '20 10:12 Shikugawa

@liberize After all we don't have to allow sharing tracer between threads because it should be lock-free. Have you considered this to have per thread?

Shikugawa avatar Feb 03 '21 05:02 Shikugawa

@Shikugawa Tracer as per thread is fine, if it is designed in this way, but notice, the sender and grpc channel should be shared across threads, typically using a memory queue to buffer.

wu-sheng avatar Feb 03 '21 06:02 wu-sheng

I have the same problem. this problem occur in my test demo. demo has only one thread. this is my demo code: `#include #include

#include "cpp2sky/propagation.h" #include "cpp2sky/tracer.h" #include "cpp2sky/tracing_context.h" #include "cpp2sky/well_known_names.h" using namespace cpp2sky; TracerConfig config;

void DoTest(int num){ std::fprintf(stdout, "start\n"); config.set_instance_name("node_0"); config.set_service_name("mesh"); config.set_address("0.0.0.0:11800"); TracerPtr _Kcbp_tracer = createInsecureGrpcTracer(config); std::fprintf(stdout, "start1\n"); while (num-- > 0) { std::fprintf(stdout, "num:%d\n", num); auto tracing_context = _Kcbp_tracer->newContext(); { std::shared_ptr<StartExitSpan> spExitAf = std::make_shared<StartExitSpan>(tracing_context, spSpan->get(), "KCBP_SKYNAME_BpcallAfter");

        auto span = tracing_context->createEntrySpan();
        span->startSpan("/grpc_client.Greeter/handle");
        if (tracing_context != nullptr) {
            span->endSpan();
        }
    }
    bool bRet = _Kcbp_tracer->report(std::move(tracing_context));
}

std::fprintf(stdout, "end\n");

}

int main() { std::fprintf(stdout, "main\n"); DoTest(3000); return 0; }`

the cpp2sky branch is main. gcc 4.9.0

xlj avatar Dec 03 '22 06:12 xlj