# DGraph4J ClientInterceptor deadline parameter takes into account connection alpha

**URL:** https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141
**Category:** Dgraph Clients
**Tags:** dgraph4j
**Created:** [July 31, 2020, 5:47pm UTC](https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141 "2020-07-31T17:47:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TarekSaid](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tareksaid/32/4236_2.png) [@TarekSaid](https://discuss.dgraph.io/u/TarekSaid)
#### Post date: [July 31, 2020, 5:47pm UTC](https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141/1 "2020-07-31T17:47:28Z")

</div>

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](http://discuss.hypermode.com/t/dgraph4j-java-client-first-connect-alpha-is-too-slow/7757).

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?

---

<div class="post-metadata">

### Author: ![abhimanyusinghgaur](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhimanyusinghgaur/32/2980_2.png) [@abhimanyusinghgaur](https://discuss.dgraph.io/u/abhimanyusinghgaur)
#### Post date: [August 2, 2020, 5:39am UTC](https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141/2 "2020-08-02T05:39:28Z")

</div>

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](http://discuss.hypermode.com/t/connection-health-check-when-creating-client/7770) issue about the `checkVersion` call. Hope to get it out by the end of this week.

---

<div class="post-metadata">

### Author: ![TarekSaid](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tareksaid/32/4236_2.png) [@TarekSaid](https://discuss.dgraph.io/u/TarekSaid)
#### Post date: [August 13, 2020, 6:35pm UTC](https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141/3 "2020-08-13T18:35:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![abhimanyusinghgaur](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhimanyusinghgaur/32/2980_2.png) [@abhimanyusinghgaur](https://discuss.dgraph.io/u/abhimanyusinghgaur)
#### Post date: [August 14, 2020, 4:28am UTC](https://discuss.dgraph.io/t/dgraph4j-clientinterceptor-deadline-parameter-takes-into-account-connection-alpha/9141/4 "2020-08-14T04:28:39Z")

</div>

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