When a plack process crashes you can end up with directories left from CGI::Compile in tmp These dirs are owned by the instance and named cgi_compile_{pid} Later on, other instances can generate the same dir name because the pid is reused. If these orphaned dirs still exist then plack locks up, unable to create/access the directory This may be a CGI::Compile bug, but if we can find a way to delete these on restart that would mitigate the issue
Related error code: Error in tempfile() using template /tmp/cgi_compile_2076/cgi_compile_XXXXX.pm: Could not create temp file /tmp/cgi_compile_2076/cgi_compile_gNjo5.pm: Permission denied at /usr/share/perl5/CGI/Compile.pm line 181.
Created attachment 109826 [details] [review] Bug 24749: Attempt to use tmp_path from koha-conf for TMPDIR for starman The issue described on this bug is triggered when a process ID is reused, but the directory belongs to another koha instance on the same server To mitigate this issue we attemtped to force plack to use an instance specific TMPDIR as CGI::Compile simply uses File::Spec::tmpdir to decide where to compile files If the folder belongs to the instance then we shouldn't have permissions issues Sadly these patches, while brilliant, do not work Attaching in the hopes someone even more brilliant can complete the work
Time for containers, Nick ?
That's an interesting one. I would say that's a CGI::Compile bug/issue. Looking at https://metacpan.org/release/CGI-Compile/source/lib/CGI/Compile.pm, it's sad that they use File::Temp for the temporary file but not for the temporary directory. Bizarre. It looks like you're setting TMPDIR in the Plack middleware, but that's probably only going to be relevant to the PSGI application rather than the Plack code around it. I'd suggest setting TMPDIR in /etc/koha/plack.psgi. You should be able to call C4::Context->temporary_directory there.
Comment on attachment 109826 [details] [review] Bug 24749: Attempt to use tmp_path from koha-conf for TMPDIR for starman Review of attachment 109826 [details] [review]: ----------------------------------------------------------------- ::: Koha/Middleware/SetEnv.pm @@ +96,5 @@ > } @setenv_headers; > > + $setenvs{TMPDIR} = C4::Context->temporary_directory; > + # See bug 24749 > + I don't think CGI::Compile will see this, as this'll be set in the PSGI application I think. ::: debian/scripts/koha-plack @@ +84,5 @@ > [ -z $PLACK_MAX_REQUESTS ] && PLACK_MAX_REQUESTS="50" > PLACK_WORKERS=$(run_safe_xmlstarlet $instancename plack_workers) > [ -z $PLACK_WORKERS ] && PLACK_WORKERS="2" > + KOHATMPDIR=$(run_safe_xmlstarlet $instancename tmp_path) > + [ -z $KOHATMPDIR ] || TMPDIR=$KOHATMPDIR You need to export TMPDIR here. Otherwise, it's just going to be localized to this script. (But really you could just define it in plack.psgi instead, which would be a more robust solution for different deployments.) You can see this by how KOHA_CONF and PERL5LIB are exported in koha-plack.