gRPC : I am getting grpc_core::Timestamp::ScopedSource::previous**(...) returned nullptr

25 Views Asked by At

I am trying to connect to gRPC server like following:

grpc::ChannelArguments ca;
ca.SetMaxReceiveMessageSize(-1);
std::shared_ptr<grpc::Channel> channel = grpc::CreateCustomChannel(ip, grpc::InsecureChannelCredentials(), ca);

Not frequenty, but some times I get this error:

Unhandled exception thrown: read access violation. grpc_core::Timestamp::ScopedSource::previous(...) returned nullptr. occurred

I am not getting what is the error. I tried to catch if any exception but could not catch it. If there is some help really appreciate it.

It would be good if there is a way to catch the exception.

1

There are 1 best solutions below

1
Yousha Aleayoub On

When getting a read access violation error, it often indicates a problem with memory access or pointer handling... You need to ensure that the pointer being accessed is valid before de-referencing it.

One method is to add a null pointer check before using the pointer. For example:

auto source = grpc_core::Timestamp::ScopedSource::previous();
if (source != nullptr) {
    // Proceed with using the source pointer.
} else {
    // Handle the case where source is nullptr.
}

And here's an example of how you can catch exceptions during the gRPC channel creation:

try {
    grpc::ChannelArguments ca;
    ca.SetMaxReceiveMessageSize(-1);
    std::shared_ptr<grpc::Channel> channel = grpc::CreateCustomChannel(ip, grpc::InsecureChannelCredentials(), ca);
} catch (const std::exception& e) {
    // Handle the exception here.
    std::cerr << "Exception caught: " << e.what() << std::endl;
}