Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

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

@anthonygego

Description

@anthonygego

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, ...)...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions