Bug #15982

race condition between multiple calls of add_additional_packages and/or remove_additional_packages

Added by alant 2018-09-26 20:30:26 . Updated 2018-10-15 17:23:21 .

Status:
Duplicate
Priority:
Normal
Assignee:
Category:
Target version:
Start date:
2018-09-26
Due date:
% Done:

0%

Feature Branch:
Type of work:
Code
Blueprint:

Starter:
Affected tool:
Additional Software Packages
Deliverable for:

Description

if the config file is written between when the packages are read and when the packages are written, this change will be overwritten by the subsequent write. You could fix this by acquiring a file lock before reading the file, for example with fcntl.flock(f, fcntl.LOCK_EX), and only releasing the lock once the file was written (example: https://gitlab.com/segfault3/onionkit/blob/master/onionkit/util.py#L21).
This way you could also get rid of the python3-atomicwrites package


Subtasks


Related issues

Has duplicate Tails - Bug #16034: ASP: Fix race condition when writing to packages file In Progress 2018-10-08

History

#1 Updated by alant 2018-09-26 20:31:52

> As far as I understand, such lock are released on close, so I don’t see how it would actually lock the config file (see https://linux.die.net/man/2/flock).
> The way the code works now, the file is opened for reading, then closed, then opened again for writing, closed, and chmod.
> We don’t even have any guarantee we actually write the the same path we read, because get_packages_list_path is called again each time.
> Am I wrong?
> Do you think we should ensure the file is only opened once?

Yes, that’s what I meant and what the flock can be used for.

#2 Updated by alant 2018-10-15 17:23:21

  • Status changed from Confirmed to Duplicate

See Bug #16034

#3 Updated by alant 2018-10-15 17:23:50

  • has duplicate Bug #16034: ASP: Fix race condition when writing to packages file added