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] client kickstart file generation may fail at startup #37

@anthonygego

Description

@anthonygego

During the route initialization process, the client_pages module is loaded to add the route to the client kickstart files.

from ictv.client.pages import client_pages

However, this module also generates the kickstart zip when it is loaded the first time.

make_system_zip()

In a multi-threaded/process environnement, the function generating the zip file is called multiple times in parallel, and may try to unlink a file that has already been unlinked by a parallel process. This ends up with a FileNotFoundError exception being raised at the application startup if such a case occurs.

def make_system_zip():
system_zip_path = os.path.join(get_root_path(), 'client', 'ks', 'system' + os.extsep + 'zip')
if os.path.exists(system_zip_path):
os.unlink(system_zip_path)
def add_file(file):
system_zip.write(os.path.join(get_root_path(), 'client', 'ks', file), arcname=file)
with ZipFile(system_zip_path, 'w') as system_zip:
add_file(os.path.join('etc', 'pam.d', 'xserver'))
add_file(os.path.join('home', 'ictv', '.xinitrc'))

Writing the file in parallel should also be avoided in case ZipFile does not implement an internal lock/is not threadsafe.

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