snap refresh while command is running may cause issues
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
snapd |
In Progress
|
Medium
|
Zygmunt Krynicki |
Bug Description
In testing a desktop snap that saves state in $HOME on close, I noticed that if I snap refresh the snap while the command is running that it will try to save its state to the previous snap version's data directory. For the snap I was testing (a browser), this resulted in a very poor user experience (the browser on restart complained about an improper shutdown).
What is happening is that:
1. on launch the snap's HOME is set to SNAP_USER_DATA, which is something like /home/user/
2. on snap refresh to 'x2', the security policy for the snap is updated for the running process such that /home/user/
3. the command in '1's environment is not changed and HOME (as well as SNAP_USER_DATA and SNAP_DATA) are all still using 'x1' in the path
4. the command tries to shutdown gracefully and save state to the 'x1' HOME and security policy blocks it
Snappy's design for rollbacks relies on the previous SNAP_DATA and SNAP_USER_DATA directories not being writable and IMHO we should not change the policy to make other snap version's data dirs writable.
The design of the snappy state engine ensures (among other things) that there is only ever one security policy in place for the snap. In snappy 15.04 this problem was (intentionally) avoided because we used snap security policy that was versioned such that the new policy would not apply until the next app invocation.
Gustavo and Zygmunt, you both advocated strongly for only one version of the policy on disk and loaded in the kernel and I recall bringing up this type of bug as a counter-argument, and if IIRC for daemons we said that snapd could simply restart them (makes perfect sense). Have you thought of the mechanism for restarting non-daemons?
Changed in snapd: | |
status: | Confirmed → Triaged |
importance: | Undecided → Medium |
Changed in snapd: | |
assignee: | nobody → Zygmunt Krynicki (zyga) |
Changed in chromium-browser (Ubuntu): | |
status: | In Progress → Fix Released |
Perhaps this was already in the design of the state engine? Eg, the state engine will periodically try to uninstall an app if it is unable to unmount the squashfs. I wonder if the security policy load (or even install) could be deferred until there were no processes running under that security label (easy to determine by examining /proc (see ps -Z).