Skip to content

Fix: client.close() does not close consensus node gRPC channels (resource leak) #2202

Description

@mohityadav8

Description

What happened

The Client.close() method only closes the mirror node gRPC channel, but does not close the consensus node channels stored in client.network.nodes.

Each _Node maintains a persistent gRPC channel (_channel) which remains open even after calling client.close() or using the client as a context manager (with Client(...)).

This leads to resource leaks and lingering open connections.

Expected behavior

All gRPC channels (including consensus node channels) should be properly closed when client.close() is called.

Fix

Added logic in Client.close() to iterate over self.network.nodes and close each node’s _channel.

This ensures all gRPC connections are properly cleaned up.

Steps to reproduce

  1. Create a Client instance
  2. Use it with a context manager:
    with Client(...) as client:
        pass

Additional context


📌 Additional context

Fix implemented by closing all `_Node._channel` instances inside `Client.close()`.

This aligns the behavior with expected resource management and prevents connection leaks.

### Hedera network

_No response_

### Version

v0.2.5

### Operating system

Windows

Metadata

Metadata

Assignees

Labels

Good First IssueIssues which are ideal for a first time or new project contributor.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions