Open YujiShen opened 4 years ago
Similar issue also happened in my async version of DB class.
@retry(reraise=True, wait=wait_fixed(1), stop=stop_after_delay(30), after=after_log(logger, logging.WARNING)
async def execute(self, query: str, values: Dict = None, cloud_logger: CloudLogger = None, log_struct: Dict = None,
error_message: str = None) -> None:
try:
await asyncio.wait_for(self.database.execute(query=query, values=values), timeout=5)
except Exception as e:
if cloud_logger and log_struct:
cloud_logger.log_error(log_struct, error_message, e)
else:
logging.error(e, exc_info=True)
raise e
It raised error and did not retry:
[2020-08-11 12:16:08 +0000] [18] [ERROR]
Traceback (most recent call last):
File "/srv/utils/async_sql.py", line 70, in execute
await asyncio.wait_for(self.database.execute(query=query, values=values), timeout=5)
File "/opt/python3.7/lib/python3.7/asyncio/tasks.py", line 449, in wait_for
raise futures.TimeoutError()
concurrent.futures._base.TimeoutError
[2020-08-11 12:16:08 +0000] [18] [WARNING] Finished call to 'utils.async_sql.AsyncDB.execute' after 5.265(s), this was the 1st time calling it.
Did I use retry correctly? Why this one did not work either?
I added tenacity for all these kind of timeout issues in my app: database queries, HTTP requests, BigQuery queries. But all of them have the similar problem I report above. It only tried once and throw the error. It did retried sometimes, but I can't find out why these failed. One common I can find is these errors are not in trace stack. Is this the reason? If so, am I able to use tenacity to retry when this happen?
I encountered the similar issue: not retry on pymysql.err.OperationalError
I add retry decorator on my database
execute
method, but when the database lost connection during the query, retry is not triggered.Here is my DB class:
Here is the log:
The request happen on 2020-08-10 15:23:17.997 EDT, I set
write_timeout
to 5s, so on 2020-08-10 19:23:23 +0000 the pymysql throw timeout error. Is it because the error is not initiated byexecute
function directly? From log you can see the exception is thrown by pymysql/connections.py. If this is the reason, how should I use tenacity to retry in this situation?