1

I am trying to configure a grpc::ClientContext as part of a syncrhonous request using GRPC. Note, without the context 'stuff' all is working fine.

My function looks like this:

grpc::Status Connection::syncLookup(Foo::LookupRequest &request, Foo::LookupResponse *response) {
    bool failure = false;
    grpc::ClientContext ctx;

    Clock::time_point now = Clock::now();
    auto time_since_epoch = std::chrono::duration_cast<Ms>(now.time_since_epoch()).count();

    if (rpc_timeout_ms_ > 0)
    {
        Clock::time_point deadline = now + Ms(rpc_timeout_ms_);
        ctx.set_deadline(deadline);
    }
    grpc::Status status = lookup_stub_->Lookup(&ctx, request, response);
    if (!status.ok())
    {
        failure = true;
        stats_worker_.record(time_since_epoch, failure, peerAddress(ctx));
        return status;
    }
    stats_worker_.record(time_since_epoch, failure, response->serverid());
    return status;
}

The error I get is:

In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:275:24: error: call to deleted constructor of 'grpc::TimePoint<time_point<steady_clock, duration<long long, ratio<1, 1000000000>>>>'
    grpc::TimePoint<T> deadline_tp(deadline);
                       ^           ~~~~~~~~
~/dev/cpp/grpc/lookupv2/lookup.cc:104:17: note: in instantiation of function template specialization 'grpc::ClientContext::set_deadline<std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<long long, std::ratio<1, 1000000000>>>>' requested here
            ctx.set_deadline(deadline);
~/.local/include/grpcpp/impl/codegen/time.h:48:3: note: 'TimePoint' has been explicitly marked deleted here
  TimePoint(const T& /*time*/) = delete;



In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:276:29: error: attempt to use a deleted function
    deadline_ = deadline_tp.raw_time();
                            ^
~/.local/include/grpcpp/impl/codegen/time.h:49:16: note: 'raw_time' has been explicitly marked deleted here
  gpr_timespec raw_time() = delete;

where it states:

~/dev/cpp/grpc/lookupv2/lookup.cc:104:17

is the line ctx.set_deadline(deadline);

From reading around the 'the internet' this is because a copy is trying to occur when there is no copy constructor present (or something). I believe the work around is to use a std_pointer or something, but now I'm slightly out of my depth now.

It seems this isn't a completely standard issue, or atleast i haven't found anything online to suggest there is a clear cut solution to this.

Any help in getting past this error would be greatly appreciated.

amlwwalker
  • 3,161
  • 4
  • 26
  • 47
  • What's `Clock::time_point`? – molbdnilo Jan 05 '23 at 13:29
  • I believe its: `using Clock = std::chrono::high_resolution_clock;` based on looking at one of the .h include (and the includes in that) – amlwwalker Jan 05 '23 at 14:45
  • @molbdnilo - this one this one https://en.cppreference.com/w/cpp/chrono/time_point – amlwwalker Jan 05 '23 at 14:50
  • According to [the source](https://grpc.github.io/grpc/cpp/grpcpp_2impl_2codegen_2time_8h_source.html), it should be `gpr_timespec` or `std::chrono::system_clock::time_point`. – molbdnilo Jan 05 '23 at 15:38
  • thank you, thats helpful. With `system_clock` it compiles - any idea why `std::chrono::high_resolution_clock` fails? I.e now trying to use `std::chrono::system_clock::time_point` ?? – amlwwalker Jan 05 '23 at 16:22
  • I'm afraid I have no insight into why GRPC works that way, but there's an (unutilized) conversion function that you probably could use - `gpr::gpr_timespec dl; grpc::TimepointHR2Timespec(deadline, &dl); ctx.set_deadline(dl);` should work with `high_resolution_clock`. Or you could specilaize the `TimePoint` template. – molbdnilo Jan 05 '23 at 16:42

0 Answers0