You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/11/07 08:04:57 UTC
[GitHub] [skywalking-python] kezhenxu94 commented on a change in pull request #79: bugfix: agent cannot reconnect after server is down
kezhenxu94 commented on a change in pull request #79:
URL: https://github.com/apache/skywalking-python/pull/79#discussion_r519150653
##########
File path: skywalking/agent/protocol/grpc.py
##########
@@ -40,22 +41,33 @@ def __init__(self):
self.channel, header_adder_interceptor('authentication', config.authentication)
)
- def cb(state):
- logger.debug('grpc channel connectivity changed, [%s -> %s]', self.state, state)
- self.state = state
- if self.connected():
- self.service_management.send_instance_props()
-
- self.channel.subscribe(cb, try_to_connect=True)
+ self.channel.subscribe(self._cb, try_to_connect=True)
self.service_management = GrpcServiceManagementClient(self.channel)
self.traces_reporter = GrpcTraceSegmentReportService(self.channel)
+ def _cb(self, state):
+ logger.debug('grpc channel connectivity changed, [%s -> %s]', self.state, state)
+ self.state = state
+ if self.connected():
+ try:
+ self.service_management.send_instance_props()
+ except grpc.RpcError:
+ self.on_error()
+
def heartbeat(self):
- self.service_management.send_heart_beat()
+ try:
+ self.service_management.send_heart_beat()
+ except grpc.RpcError:
+ self.on_error()
def connected(self):
return self.state == grpc.ChannelConnectivity.READY
+ def on_error(self):
+ traceback.print_exc()
+ self.channel.unsubscribe(self._cb)
+ self.channel.subscribe(self._cb, try_to_connect=True)
Review comment:
The reason why it didn't reconnect before, is that the `try_to_connect` only takes effect in this single subscription, once the channel is connected, it is set to `False`, therefore we re-subscribe once the server closes this connection.
From https://github.com/grpc/grpc/issues/6478#issuecomment-226951042
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org