Encountered a bug with temp files when multiple WebApp's are hosted on the same server
clemensm opened this issue · comments
Hello
I've recently encountred a problem when installing a new application on one of my servers that was related to Plug.Upload
. On that server I'm hosting multiple small applications, and each application is run as a systemd service with it's own unix user. So e.g.
app A is run as user A, app B as user B etc.
Now the latest app I've installed was using LiveUpload
from Phoenix, but after installation the uploads would fail. Closer examination showed that the Plug.Upload.ensure_tmp/0
function creates a temporaray folder in the global tmp
folder called plug-<pid_here>
. Now the problem was that one of the other applications had already created a folder with exactly the same name, but which was owned by a different user, so the new application could not write into that folder.
I've solved this by manually deleting the folder, but my question is if it would make sense to try to generate a more unique name instead of simply using the <PID>
? I'm not very well versed with the code of the Plug
library and if there is the assumption that there will be only one instance of it running per server all the time, so this more or less just a proposal/question in this regard.
Thanks for your consideration already.
You can set the tmp folder with PLUG_TMPDIR - https://hexdocs.pm/plug/1.13.6/Plug.Parsers.html#module-file-handling
For now, I think PLUG_TMPDIR
is the way to go, even to give more direct control over which files are used by different apps. Thank you for the suggestion @damir!
thanks for the suggestion, I wasn't aware of that option. That will do for me