OSDN Git Service

Fix error handling in temp-file deletion with log_temp_files active.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Nov 2010 03:14:48 +0000 (22:14 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 9 Nov 2010 03:14:48 +0000 (22:14 -0500)
commit54428dbe90cf11d17439acad9b8dcf375a14819d
treedc74528622698a71cfec16393560f83898ef59cb
parent854ae8c3a6bab2053f8bdbc453787be878ce8c81
Fix error handling in temp-file deletion with log_temp_files active.

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.
src/backend/storage/file/fd.c