-
Notifications
You must be signed in to change notification settings - Fork 5
[concurrency] client kickstart file generation may fail at startup #37
Description
During the route initialization process, the client_pages module is loaded to add the route to the client kickstart files.
Line 7 in 97c8dcb
| from ictv.client.pages import client_pages |
However, this module also generates the kickstart zip when it is loaded the first time.
ICTV/ictv/client/pages/client_pages.py
Line 84 in 97c8dcb
| 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.
ICTV/ictv/client/pages/client_pages.py
Lines 54 to 64 in 97c8dcb
| 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.