hiero-ledger / hiero-ledger/hiero-sdk-java

Client.close() times out if subscribing to mirror gRPC API

Open
#1,182 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
264
Forks
192
Avg merge
2d
Merged PRs (30d)
39

Description

### Description

Attempting to close a `Client` in the middle of a mirror node gRPC API streaming query will block for `closeTimeout` then throw a timeout exception. Since you can't have a subscription without the `Channel` that the `Client` manages for it, it's expected that the SDK would register any subscriptions and close them gracefully on `close()`. Requiring the user to manually unsubscribe from the gRPC query is awkward and error-prone since it can only unsubscribe during the happy path or if close is called manually. In the below, it can't just unsubscribe once in a finally block.

### Steps to reproduce

```java
try (Client client = Client.forMainnet()) {
...
new TopicMessageQuery().setTopicId(topicId).subscribe(client, r -> {});
}
```

### Additional context

```
2022-10-15T19:12:06.518-0600 ERROR ForkJoinPool-2-worker-9 i.g.i.ManagedChannelImpl [Channel<13>: (previewnet.mirrornode.hedera.com:443)] Uncaught exception in the SynchronizationContext. Panic! io.grpc.StatusRuntimeException: UNKNOWN: Uncaught exception in the SynchronizationContext. Re-thrown.
at io.grpc.Status.asRuntimeException(Status.java:530)
at io.grpc.internal.RetriableStream$1.uncaughtException(RetriableStream.java:75)
at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:97)
at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:127)
2022-10-15T19:12:06.522-0600 ERROR ForkJoinPool-2-worker-9 c.h.m.t.e.a.c.SDKClient startup probe: java.util.concurrent.TimeoutException: Failed to properly shutdown all channels
at com.hedera.hashgraph.sdk.BaseNetwork.awaitClose(BaseNetwork.java:605)
at com.hedera.hashgraph.sdk.Client.close(Client.java:1305)
at com.hedera.hashgraph.sdk.Client.close(Client.java:1271)
```

### Hedera network

mainnet

### Version

v2.18.0

### Operating system

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.