refactor: share single ClientChannel between Hub and HubAdmin

Initial scaffold accidentally created three separate gRPC
channels (one for each of `_channel`, `_hub`, `_admin`).
Refactor to a single shared channel — cleaner, fewer file
descriptors, and `close()` actually closes everything now.
Idle timeout raised to 5 minutes so polling-style page loops
don't keep reconnecting.

No public-API change.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-05-05 22:51:19 +02:00
parent a2e3f4514a
commit 4b67055fc7

View file

@ -50,38 +50,23 @@ class HubClient {
final grpc_hub.HubClient _hub; final grpc_hub.HubClient _hub;
final grpc_hub.HubAdminClient _admin; final grpc_hub.HubAdminClient _admin;
HubClient({this.endpoint = const HubEndpoint()}) HubClient._(this.endpoint, this._channel)
: _channel = ClientChannel( : _hub = grpc_hub.HubClient(_channel),
_admin = grpc_hub.HubAdminClient(_channel);
factory HubClient({HubEndpoint endpoint = const HubEndpoint()}) {
final channel = ClientChannel(
endpoint.host, endpoint.host,
port: endpoint.port, port: endpoint.port,
options: ChannelOptions( options: ChannelOptions(
credentials: endpoint.secure credentials: endpoint.secure
? const ChannelCredentials.secure() ? const ChannelCredentials.secure()
: const ChannelCredentials.insecure(), : const ChannelCredentials.insecure(),
), idleTimeout: const Duration(minutes: 5),
),
_hub = grpc_hub.HubClient(
ClientChannel(
endpoint.host,
port: endpoint.port,
options: ChannelOptions(
credentials: endpoint.secure
? const ChannelCredentials.secure()
: const ChannelCredentials.insecure(),
),
),
),
_admin = grpc_hub.HubAdminClient(
ClientChannel(
endpoint.host,
port: endpoint.port,
options: ChannelOptions(
credentials: endpoint.secure
? const ChannelCredentials.secure()
: const ChannelCredentials.insecure(),
),
), ),
); );
return HubClient._(endpoint, channel);
}
/// Liveness probe. Returns true when the hub responds with /// Liveness probe. Returns true when the hub responds with
/// SERVING. False on any failure (includes connection refused). /// SERVING. False on any failure (includes connection refused).