UCL-INGI / ICTV

ICTV is a simple content management system for digital signage on multiple screens.
Other
15 stars 5 forks source link

[concurrency] client kickstart file generation may fail at startup #37

Open anthonygego opened 2 years ago

anthonygego commented 2 years ago

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

https://github.com/UCL-INGI/ICTV/blob/97c8dcba78d02d55da1422dfce3a69a552811c26/ictv/flask/mapping.py#L7

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

https://github.com/UCL-INGI/ICTV/blob/97c8dcba78d02d55da1422dfce3a69a552811c26/ictv/client/pages/client_pages.py#L84

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.

https://github.com/UCL-INGI/ICTV/blob/97c8dcba78d02d55da1422dfce3a69a552811c26/ictv/client/pages/client_pages.py#L54-L64

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