File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed
Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -354,33 +354,31 @@ async def acquire(self) -> APNsBaseClientProtocol:
354354 for connection in self .connections :
355355 if not connection .is_busy :
356356 return connection
357- else :
358- await self ._lock . acquire ()
357+
358+ async with self ._lock :
359359 for connection in self .connections :
360360 if not connection .is_busy :
361- self ._lock .release ()
362361 return connection
363362 if len (self .connections ) < self .max_connections :
364363 try :
365364 connection = await self .create_connection ()
366365 except Exception as e :
367366 logger .error ("Could not connect to server: %s" , str (e ))
368- self ._lock .release ()
369367 raise ConnectionError ()
370368 self .connections .append (connection )
371369 logger .info (
372370 "Connection established (total: %d)" , len (self .connections )
373371 )
374- self ._lock .release ()
375372 return connection
376- else :
377- self ._lock .release ()
378- logger .warning ("Pool is busy, wait..." )
379- while True :
380- await asyncio .sleep (0.01 )
381- for connection in self .connections :
382- if not connection .is_busy :
383- return connection
373+
374+ logger .warning (
375+ "Pool is completely busy and has hit max connections, retrying..."
376+ )
377+ while True :
378+ await asyncio .sleep (0.01 )
379+ for connection in self .connections :
380+ if not connection .is_busy :
381+ return connection
384382
385383 async def send_notification (
386384 self , request : NotificationRequest
You can’t perform that action at this time.
0 commit comments