@@ -601,8 +601,16 @@ def call_on_each_event(
601
601
if narrow is None :
602
602
narrow = []
603
603
604
- def do_register (backoff : RandomExponentialBackoff ) -> Tuple [str , int ]:
605
- while backoff .keep_going ():
604
+ queue_id = None
605
+ # NOTE: Back off exponentially to cover against potential bugs in this
606
+ # library causing a DoS attack against a server when getting errors
607
+ # (explicit values listed for clarity)
608
+ backoff = RandomExponentialBackoff (maximum_retries = 10 ,
609
+ timeout_success_equivalent = 300 ,
610
+ delay_cap = 90 )
611
+ while backoff .keep_going ():
612
+ # Ensure event queue exists (or continues to do so)
613
+ if queue_id is None :
606
614
if event_types is None :
607
615
res = self .register ()
608
616
else :
@@ -612,24 +620,14 @@ def do_register(backoff: RandomExponentialBackoff) -> Tuple[str, int]:
612
620
if self .verbose :
613
621
print ("Server returned error:\n %s" % res ['msg' ])
614
622
backoff .fail ()
623
+ continue
615
624
else :
616
625
backoff .succeed ()
617
- return (res ['queue_id' ], res ['last_event_id' ])
618
-
619
- queue_id = None
620
- # Make long-polling requests with `get_events`. Once a request
621
- # has received an answer, pass it to the callback and before
622
- # making a new long-polling request.
623
- # NOTE: Back off exponentially to cover against potential bugs in this
624
- # library causing a DoS attack against a server when getting errors
625
- # (explicit values listed for clarity)
626
- backoff = RandomExponentialBackoff (maximum_retries = 10 ,
627
- timeout_success_equivalent = 300 ,
628
- delay_cap = 90 )
629
- while backoff .keep_going ():
630
- if queue_id is None :
631
- (queue_id , last_event_id ) = do_register (backoff )
626
+ queue_id , last_event_id = res ['queue_id' ], res ['last_event_id' ]
632
627
628
+ # Make long-polling requests with `get_events`. Once a request
629
+ # has received an answer, pass it to the callback and before
630
+ # making a new long-polling request.
633
631
res = self .get_events (queue_id = queue_id , last_event_id = last_event_id )
634
632
if 'error' in res ['result' ]:
635
633
if res ["result" ] == "http-error" :
0 commit comments