Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of retry attempts when connecting to the database #26

Open
GSvensk opened this issue Sep 11, 2020 · 0 comments
Open

Limit number of retry attempts when connecting to the database #26

GSvensk opened this issue Sep 11, 2020 · 0 comments
Assignees

Comments

@GSvensk
Copy link

GSvensk commented Sep 11, 2020

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
@ferras ferras self-assigned this Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants