Debugging C++ Async Callback API calls

107 views
Skip to first unread message

Konstantina Skovola

unread,
Mar 21, 2025, 11:26:04 AMMar 21
to grpc.io

Hi!

I am using the grpc c++ async callback API for my application and I don't know how to get more details about the following error:

On the server side I write the streaming response like this:

```
cta::xrd::Response *header = new cta::xrd::Response();
header->set_type(cta::xrd::Response::RSP_SUCCESS);
header->set_show_header(cta::admin::HeaderType::TAPE_LS);
response.set_allocated_header(header); // now the message takes ownership of the allocated object, we don't need to free header

std::cout << "about to call StartWrite on the server side" << std::endl;
StartWrite(&response); // this will trigger OnWriteDone
std::cout << "called StartWrite on the server" << std::endl;
```

On the client side, I make the call like this
```
std::cout << "In CtaAdminClientReadReactor, about to call the async GenericAdminStream" << std::endl;
client_stub->async()->GenericAdminStream(&m_context, request, this);
std::cout << "Started the request to the server by calling GenericAdminStream" << std::endl;
StartRead(&m_response); // where to store the received response?
std::cout << "In CtaAdminClientReadReactor, called startRead" << std::endl;
StartCall(); // activate the RPC!
std::cout << "In CtaAdminClientReadReactor, called StartCall()" << std::endl;
```

and then read the streaming response:

```
virtual void OnReadDone(bool ok) override {
        std::cout << "In CtaAdminCmdStream, inside OnReadDone() " << std::endl;
        if (!ok) {
            std::cout << "Something went wrong with reading the response in the client" << std::endl;
        } else {
            // if this is the header, print the formatted header
            if (m_response.has_header()) {
                std::cout << "We received the header on the client side " << std::endl;
                switch (m_response.header().type()) {
.......
```

Using debug prints, from the output, I can see that on the server side, StartWrite() is called just once, then on the client side, the first time OnReadDone is called, it goes into the “not ok” branch.

The error code and message the rpc returns is “Error code: 14, Error message: Socket closed”.

How can I get more insights on where things go wrong? I have enabled debug logging but it seems not much is logged by the async callback API.

Any pointers will be greatly appreciated!
Many thanks,
Konstantina

yas...@google.com

unread,
Apr 1, 2025, 10:01:50 PMApr 1
to grpc.io
Hi, Please take a look at https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for information on how to get more detailed logging.

If something in gRPC triggered the socket closure, you might see some more details in the logs. This might also be a case where gRPC did not do a good job of propagating the real error, and if that's the case, please raise an issue at https://github.com/grpc/grpc/. On the other hand, if this is something that was caused by a network failure or remote trouble, gRPC logs won't be able to tell you much.

Konstantina Skovola

unread,
May 7, 2025, 7:21:06 AMMay 7
to grpc.io

Thank you for the reply. I think my problem was due to me not using correct lifetimes, the “response” I was using was not as long-lived as the rpc call. Anyway, it is resolved now.

Reply all
Reply to author
Forward
0 new messages