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

[concurrency] templates and themes loading may fail at startup #36

Open
anthonygego opened this issue Aug 2, 2022 · 0 comments
Open

Comments

@anthonygego
Copy link
Member

Templates are themes table are re-initialized at application startup in a transaction that empties the database table and feeds it using the discovered files.

sqlhub.doInTransaction(load_templates_and_themes)

ICTV/ictv/app.py

Lines 87 to 90 in 97c8dcb

def load_templates_and_themes():
Template.deleteMany(None)
for template in next((os.walk(os.path.join(get_root_path(), 'renderer/templates/'))))[2]:
Template(name=template.replace('.html', ''))

In a multi-process setup with (u)wsgi and lazy-apps set to true, multiple transactions may be performed in parallel during application startup. This leads to the failure and rollback of one or several of them because the first one may be in the commit stage while the other is in the processing stage.

This is not destructive as the transaction is rolled back but sqlobject.dberrors.DuplicateEntryError as well as psycopg2.errors.UniqueViolation exceptions are raised and never caught, making the app crash.

While we could logically accept such a failure and pass on sqlobject.dberrors.DuplicateEntryError, it is not sufficient to catch the sqlobject backend underlying exception (psyscopg in the case of postgre). Catching all exceptions and passing could lead to more instable behaviour (I/O erros, ...)...

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

1 participant