postgres.git / summary / log / commit / refs

commit    8a07e5bd82486b024e58417c09da193c275b13d3
Author:   Thomas Munro <tmunro@postgresql.org>
Date:     Mon Feb 15 00:32:58 2021 +0000
First released in: 14.0, 9.6.22, 10.17, 11.12, 12.7, 13.3

    Hold interrupts while running dsm_detach() callbacks.
    
    While cleaning up after a parallel query or parallel index creation that
    created temporary files, we could be interrupted by a statement timeout.
    The error handling path would then fail to clean up the files when it
    ran dsm_detach() again, because the callback was already popped off the
    list.  Prevent this hazard by holding interrupts while the cleanup code
    runs.
    
    Thanks to Heikki Linnakangas for this suggestion, and also to Kyotaro
    Horiguchi, Masahiko Sawada, Justin Pryzby and Tom Lane for discussion of
    this and earlier ideas on how to fix the problem.
    
    Back-patch to all supported releases.
    
    Reported-by: Justin Pryzby <pryzby@telsasoft.com>
    Discussion: https://postgr.es/m/20191212180506.GR2082@telsasoft.com


src/backend/storage/ipc/dsm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index 6dd41bdfa59..385890cd924 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -706,8 +706,12 @@ dsm_detach(dsm_segment *seg) /* * Invoke registered callbacks. Just in case one of those callbacks * throws a further error that brings us back here, pop the callback - * before invoking it, to avoid infinite error recursion. + * before invoking it, to avoid infinite error recursion. Don't allow + * interrupts while running the individual callbacks in non-error code + * paths, to avoid leaving cleanup work unfinished if we're interrupted by + * a statement timeout or similar. */ + HOLD_INTERRUPTS(); while (!slist_is_empty(&seg->on_detach)) { slist_node *node; @@ -723,6 +727,7 @@ dsm_detach(dsm_segment *seg) function(seg, arg); } + RESUME_INTERRUPTS(); /* * Try to remove the mapping, if one exists. Normally, there will be, but [parent: cc7ea0717b12]