DGraph4J ClientInterceptor deadline parameter takes into account connection alpha

java version: 1.8
spring version: 5.0.6.RELEASE
dgraph4j version: 20.03.0

I have the following configuration for the DGraph client:

@Configuration
public class DGraphConfig {
    @Value("${dgraph.url}")
    private String url;

    @Value("${dgraph.port}")
    private int port;

    @Value("${dgraph.timeout}")
    private int timeout;

    public ManagedChannel managedChannel() {
        return ManagedChannelBuilder.forAddress(url, port).usePlaintext().build();
    }

    public ClientInterceptor timeout() {
        return new ClientInterceptor() {
            @Override
            public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
                MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
                return next.newCall(method, callOptions.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS));
            }
        };
    }

    public DgraphGrpc.DgraphStub stub() {
        return DgraphGrpc.newStub(managedChannel()).withInterceptors(timeout());
    }

    @Bean
    @Primary
    public DgraphAsyncClient client() {
        return new DgraphAsyncClient(stub());
    }
}

I’ve set up a timeout of 500ms at first, then 1 second. But the deadline for the first query is always reached. I suspect it’s due to Dgraph4j java client first connect alpha is too slow.

I could set a timeout of 3 seconds, but it doesn’t make much sense, as it’s only slow the first time, subsequent calls are much faster and therefore do not need such a high timeout setting. If the first connect alpha is so slow, is there a way for the deadline to only start counting when all the steps to configure the connection are done?

Hey @TarekSaid

The Java client is soon going to have a checkVersion method on client, which will help you setup a gRPC connection before performing any queries/mutations. Then I guess, you won’t need to setup any timeout for queries. You would just call checkVersion for the first time, then do any queries/mutations. If any timeouts are required, they would go to checkVersion as it will only be a one-time call.

Please refer this issue about the checkVersion call. Hope to get it out by the end of this week.

Gi @abhimanyusinghgaur, thanks for the reply! I’ll mark the issue as solved, then.

FYI, dgraph4j v20.03.1 was released with the checkVersion call. You can upgrade your build file to use the new version.