puppet-openldap icon indicating copy to clipboard operation
puppet-openldap copied to clipboard

Don't delete temporary file before using it

Open justafish opened this issue 1 year ago • 1 comments

Pull Request (PR) description

I encountered an LDAP error 80 (LDAP_OTHER) whilst adding SSL certificates:

 class { 'openldap::server':
        ssl_cert   => '/etc/ssl/certs/foo.com.crt',
        ssl_key    => '/etc/ssl/private/foo.com.key',
        ssl_ca     => '/etc/ssl/certs/foo.com.ca-bundle',
    }

This Pull Request (PR) fixes the following issues

Doesn't delete temporary files before they're used

justafish avatar Jun 18 '24 17:06 justafish

I am not sure to follow: closing a (Temp)File does not remove it.

According to the documentation:

When a Tempfile object is garbage collected, or when the Ruby interpreter exits, its associated temporary file is automatically deleted

In this case, the garbage collection of the object would not happen before the execution flow exited the function that created the temporary file, which is the scope of the local variable.

We explicitly #close the file to make sure data written to it was flushed to disk before running a command that depend on the file content. We can probably do this another way (there is probably a #flush method), but the neat result should be the same, and as we will not write more data it feels more natural to just close the file IMHO.

Maybe you experienced some race condition the module does not handle correctly? Are you able to reproduce your error? Can you provide a manifest that we can use to reproduce the error?

smortex avatar Jun 20 '24 08:06 smortex