cpp2sky
cpp2sky copied to clipboard
sendSegment is not thread-safe
sendSegment is not thread-safe because GrpcAsyncSegmentReporterStream::clearPendingMessages
is not
which causes SIGABRT with proto_buffer_writer.h:65 assertion failed: !byte_buffer->Valid()
@Shikugawa Do we open multiple threads for sending the segment?
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.
@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 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.
I have the same problem. this problem occur in my test demo. demo has only one thread.
this is my demo code:
`#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