metaflow-service icon indicating copy to clipboard operation
metaflow-service copied to clipboard

Limit number of retry attempts when connecting to the database

Open GSvensk opened this issue 3 years ago • 0 comments

On startup, infinite attempts are made to connect to postgres. When an attempt fails there is no error message.

As I understand it, there exists an attempt at a retry mechanism which limits the number of postgres connection attempts to 3. Afterwards, the exception is supposed to be raised. Unfortunately, this does not work as currently implemented and the exception is never raised.

There is also a todo associated with adding a proper error message. All of this can be found in postgres_async_db.py in the _init() method.

Proposed fix:

        retries = 3
        attempt = 0
        while True:
            try:
                self.pool = await aiopg.create_pool(dsn)
                for table in self.tables:
                    await table._init()
            except Exception as e:
                attempt += 1
                print("Could not connect to database, attempt", attempt, "out of", retries, "\n Cause:", e)
                if attempt == retries:
                    raise e
                time.sleep(1)
                continue
            break

GSvensk avatar Sep 11 '20 14:09 GSvensk