• Tom Lane's avatar
    Fix error handling in temp-file deletion with log_temp_files active. · 54428dbe
    Tom Lane authored
    The original coding in FileClose() reset the file-is-temp flag before
    unlinking the file, so that if control came back through due to an error,
    it wouldn't try to unlink the file twice.  This was correct when written,
    but when the log_temp_files feature was added, the logging action was put
    in between those two steps.  An error occurring during the logging action
    --- such as a query cancel --- would result in the unlink not getting done
    at all, as in recent report from Michael Glaesemann.
    
    To fix this, make sure that we do both the stat and the unlink before doing
    anything that could conceivably CHECK_FOR_INTERRUPTS.  There is a judgment
    call here, which is which log message to emit first: if you can see only
    one, which should it be?  I chose to log unlink failure at the risk of
    losing the log_temp_files log message --- after all, if the unlink does
    fail, the temp file is still there for you to see.
    
    Back-patch to all versions that have log_temp_files.  The code was OK
    before that.
    54428dbe
fd.c 50.9 KB