This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch fix_reconnect
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit c2230297954249beac879eaa7656118acd2d3b4b
Author: huawei <[email protected]>
AuthorDate: Tue Sep 8 23:22:22 2020 +0800

    fix cannot reconnect
---
 skywalking/agent/__init__.py | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/skywalking/agent/__init__.py b/skywalking/agent/__init__.py
index 8ed9759..a57c47e 100644
--- a/skywalking/agent/__init__.py
+++ b/skywalking/agent/__init__.py
@@ -32,18 +32,26 @@ logger = logging.getLogger(__name__)
 def __heartbeat():
     while not __finished.is_set():
         if connected():
-            __protocol.heartbeat()
-
-        __finished.wait(30 if connected() else 3)
+            try:
+                __protocol.heartbeat()
+                __finished.wait(3)
+            except Exception as e:
+                pass
+        else:
+            connect()
+            __finished.wait(30)
 
 
 def __report():
     while not __finished.is_set():
         if connected():
-            __protocol.report(__queue)
-            break
+            try:
+                __protocol.report(__queue)
+            except Exception as e:
+                pass
         else:
-            __finished.wait(1)
+            connect()
+            __finished.wait(30)
 
 
 __heartbeat_thread = Thread(name='HeartbeatThread', target=__heartbeat, 
daemon=True)
@@ -55,6 +63,11 @@ __started = False
 
 
 def __init():
+    connect()
+    plugins.install()
+
+
+def connect():
     global __protocol
     if config.protocol == 'grpc':
         from skywalking.agent.protocol.grpc import GrpcProtocol
@@ -63,8 +76,6 @@ def __init():
         from skywalking.agent.protocol.http import HttpProtocol
         __protocol = HttpProtocol()
 
-    plugins.install()
-
 
 def start():
     global __started

Reply via email to