File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,7 @@ def __acceptIncomingConnection(self, svcName=False):
200200 services at the same time
201201 """
202202 sel = self .__getListeningSelector (svcName )
203+ throttleExpires = None
203204 while self .__alive :
204205 clientTransport = None
205206 try :
@@ -223,12 +224,19 @@ def __acceptIncomingConnection(self, svcName=False):
223224 gLogger .warn (f"Client connected from banned ip { clientIP } " )
224225 clientTransport .close ()
225226 continue
227+ # Handle throttling
228+ if self .__services [svcName ].wantsThrottle and throttleExpires is None :
229+ throttleExpires = time .time () + THROTTLE_SERVICE_SLEEP_SECONDS
230+ if throttleExpires :
231+ if time .time () > throttleExpires :
232+ throttleExpires = None
233+ else :
234+ gLogger .warn ("Rejecting client due to throttling" , str (clientTransport .getRemoteAddress ()))
235+ clientTransport .close ()
236+ continue
226237 # Handle connection
227238 self .__stats .connectionStablished ()
228239 self .__services [svcName ].handleConnection (clientTransport )
229- while self .__services [svcName ].wantsThrottle :
230- gLogger .warn ("Sleeping as service requested throttling" , svcName )
231- time .sleep (THROTTLE_SERVICE_SLEEP_SECONDS )
232240 # Renew context?
233241 now = time .time ()
234242 renewed = False
You can’t perform that action at this time.
0 commit comments