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

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

Comments

@anthonygego
Copy link
Member

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.

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