Mercurial > p > roundup > code
diff roundup/backends/sessions_dbm.py @ 5732:0e6ed3d72f92
Rest rate limiting code first commit. It is a bit rough and turned off
by default.
The current code is lossy. If client connections are fast enough, the
rate limiting code doesn't count every connection. So the client can
get more connections than configured if they are fast enough.
5-20% of the connections are not recorded.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 25 May 2019 16:50:25 -0400 |
| parents | 0b154486ed38 |
| children | abee2c2c822e |
line wrap: on
line diff
--- a/roundup/backends/sessions_dbm.py Sat May 25 14:39:43 2019 -0400 +++ b/roundup/backends/sessions_dbm.py Sat May 25 16:50:25 2019 -0400 @@ -129,7 +129,26 @@ # open the database with the correct module dbm = __import__(db_type) - return dbm.open(path, mode) + + retries_left=15 + while True: + try: + handle = dbm.open(path, mode) + break + except OSError as e: + # Primarily we want to catch and retry: + # [Errno 11] Resource temporarily unavailable retry + # FIXME: make this more specific + if retries_left < 0: + # We have used up the retries. Reraise the exception + # that got us here. + raise + else: + # delay retry a bit + time.sleep(0.01) + retries_left = retries_left -1 + continue # the while loop + return handle def commit(self): pass
