From c35588d01fd9a0169a819a20c261702f07332c37 Mon Sep 17 00:00:00 2001 From: sparky8512 <76499194+sparky8512@users.noreply.github.com> Date: Sat, 6 Nov 2021 20:16:50 -0700 Subject: [PATCH] Fixes related to failed grpc network connection Add timeouts to all gRPC remote calls and bump yagrc package requirement to a version that does same for the reflection service, as well as fixing a state issue around failed lazy import resolution. This should address the script hang symptom on issue #36. --- dump_dish_status.py | 2 +- requirements.txt | 2 +- starlink_grpc.py | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dump_dish_status.py b/dump_dish_status.py index 4992d05..dbeddf1 100644 --- a/dump_dish_status.py +++ b/dump_dish_status.py @@ -11,7 +11,7 @@ from spacex.api.device import dish_pb2 # call channel.close() when you're done with the gRPC connection. with grpc.insecure_channel("192.168.100.1:9200") as channel: stub = device_pb2_grpc.DeviceStub(channel) - response = stub.Handle(device_pb2.Request(get_status={})) + response = stub.Handle(device_pb2.Request(get_status={}), timeout=10) # Dump everything print(response) diff --git a/requirements.txt b/requirements.txt index 55716c9..72b189f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ grpcio>=1.12.0 grpcio-tools>=1.20.0 protobuf>=3.6.0 -yagrc>=1.1.0 +yagrc>=1.1.1 paho-mqtt>=1.5.1 influxdb>=5.3.1 pypng>=0.0.20 diff --git a/starlink_grpc.py b/starlink_grpc.py index 849ffb5..7aef35f 100644 --- a/starlink_grpc.py +++ b/starlink_grpc.py @@ -351,6 +351,10 @@ from spacex.api.device import device_pb2 from spacex.api.device import device_pb2_grpc from spacex.api.device import dish_pb2 +# Max wait time for gRPC request completion, in seconds. This is just to +# prevent hang if the connection goes dead without closing. +REQUEST_TIMEOUT = 10 + HISTORY_FIELDS = ("pop_ping_drop_rate", "pop_ping_latency_ms", "downlink_throughput_bps", "uplink_throughput_bps") @@ -546,7 +550,7 @@ def get_status(context=None): if imports_pending: resolve_imports(channel) stub = device_pb2_grpc.DeviceStub(channel) - response = stub.Handle(device_pb2.Request(get_status={})) + response = stub.Handle(device_pb2.Request(get_status={}), timeout=REQUEST_TIMEOUT) return response.dish_get_status return call_with_channel(grpc_call, context=context) @@ -816,7 +820,7 @@ def get_history(context=None): if imports_pending: resolve_imports(channel) stub = device_pb2_grpc.DeviceStub(channel) - response = stub.Handle(device_pb2.Request(get_history={})) + response = stub.Handle(device_pb2.Request(get_history={}), timeout=REQUEST_TIMEOUT) return response.dish_get_history return call_with_channel(grpc_call, context=context) @@ -1209,7 +1213,8 @@ def get_obstruction_map(context=None): if imports_pending: resolve_imports(channel) stub = device_pb2_grpc.DeviceStub(channel) - response = stub.Handle(device_pb2.Request(dish_get_obstruction_map={})) + response = stub.Handle(device_pb2.Request(dish_get_obstruction_map={}), + timeout=REQUEST_TIMEOUT) return response.dish_get_obstruction_map return call_with_channel(grpc_call, context=context)