@@ -79,21 +79,28 @@ def heartbeat(self):
7979
8080 except grpc .RpcError :
8181 self .on_error ()
82+ raise
8283
8384 def on_error (self ):
8485 traceback .print_exc () if logger .isEnabledFor (logging .DEBUG ) else None
8586 self .channel .unsubscribe (self ._cb )
8687 self .channel .subscribe (self ._cb , try_to_connect = True )
8788
8889 def report (self , queue : Queue , block : bool = True ):
89- start = time ()
90+ start = None
9091
9192 def generator ():
93+ nonlocal start
94+
9295 while True :
9396 try :
94- timeout = config .QUEUE_TIMEOUT - int (time () - start ) # type: int
95- if timeout <= 0 : # this is to make sure we exit eventually instead of being fed continuously
96- return
97+ timeout = config .QUEUE_TIMEOUT # type: int
98+ if not start : # make sure first time through queue is always checked
99+ start = time ()
100+ else :
101+ timeout -= int (time () - start )
102+ if timeout <= 0 : # this is to make sure we exit eventually instead of being fed continuously
103+ return
97104 segment = queue .get (block = block , timeout = timeout ) # type: Segment
98105 except Empty :
99106 return
@@ -145,16 +152,23 @@ def generator():
145152 self .traces_reporter .report (generator ())
146153 except grpc .RpcError :
147154 self .on_error ()
155+ raise # reraise so that incremental reconnect wait can process
148156
149157 def report_log (self , queue : Queue , block : bool = True ):
150- start = time ()
158+ start = None
151159
152160 def generator ():
161+ nonlocal start
162+
153163 while True :
154164 try :
155- timeout = config .QUEUE_TIMEOUT - int (time () - start ) # type: int
156- if timeout <= 0 :
157- return
165+ timeout = config .QUEUE_TIMEOUT # type: int
166+ if not start : # make sure first time through queue is always checked
167+ start = time ()
168+ else :
169+ timeout -= int (time () - start )
170+ if timeout <= 0 : # this is to make sure we exit eventually instead of being fed continuously
171+ return
158172 log_data = queue .get (block = block , timeout = timeout ) # type: LogData
159173 except Empty :
160174 return
@@ -169,16 +183,23 @@ def generator():
169183 self .log_reporter .report (generator ())
170184 except grpc .RpcError :
171185 self .on_error ()
186+ raise
172187
173188 def send_snapshot (self , queue : Queue , block : bool = True ):
174- start = time ()
189+ start = None
175190
176191 def generator ():
192+ nonlocal start
193+
177194 while True :
178195 try :
179- timeout = config .QUEUE_TIMEOUT - int (time () - start ) # type: int
180- if timeout <= 0 :
181- return
196+ timeout = config .QUEUE_TIMEOUT # type: int
197+ if not start : # make sure first time through queue is always checked
198+ start = time ()
199+ else :
200+ timeout -= int (time () - start )
201+ if timeout <= 0 : # this is to make sure we exit eventually instead of being fed continuously
202+ return
182203 snapshot = queue .get (block = block , timeout = timeout ) # type: TracingThreadSnapshot
183204 except Empty :
184205 return
@@ -199,3 +220,4 @@ def generator():
199220 self .profile_channel .send (generator ())
200221 except grpc .RpcError :
201222 self .on_error ()
223+ raise
0 commit comments