Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cb9a0c7

Browse files
committed
Teach on_exit_reset() to discard pending cleanups for dsm.
If a postmaster child invokes fork() and then calls on_exit_reset, that should be sufficient to let it exit() without breaking anything, but dynamic shared memory broke that by not updating on_exit_reset() to discard callbacks registered with dynamic shared memory segments. Per investigation of a complaint from Tom Lane.
1 parent 7704944 commit cb9a0c7

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/backend/storage/ipc/dsm.c

+31
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,37 @@ cancel_on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function,
979979
}
980980
}
981981

982+
/*
983+
* Discard all registered on-detach callbacks without executing them.
984+
*/
985+
void
986+
reset_on_dsm_detach(void)
987+
{
988+
dlist_iter iter;
989+
990+
dlist_foreach(iter, &dsm_segment_list)
991+
{
992+
dsm_segment *seg = dlist_container(dsm_segment, node, iter.cur);
993+
994+
/* Throw away explicit on-detach actions one by one. */
995+
while (!slist_is_empty(&seg->on_detach))
996+
{
997+
slist_node *node;
998+
dsm_segment_detach_callback *cb;
999+
1000+
node = slist_pop_head_node(&seg->on_detach);
1001+
cb = slist_container(dsm_segment_detach_callback, node, node);
1002+
pfree(cb);
1003+
}
1004+
1005+
/*
1006+
* Decrementing the reference count is a sort of implicit on-detach
1007+
* action; make sure we don't do that, either.
1008+
*/
1009+
seg->control_slot = INVALID_CONTROL_SLOT;
1010+
}
1011+
}
1012+
9821013
/*
9831014
* Create a segment descriptor.
9841015
*/

src/backend/storage/ipc/ipc.c

+1
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,5 @@ on_exit_reset(void)
400400
before_shmem_exit_index = 0;
401401
on_shmem_exit_index = 0;
402402
on_proc_exit_index = 0;
403+
reset_on_dsm_detach();
403404
}

src/include/storage/dsm.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ extern void on_dsm_detach(dsm_segment *seg,
4343
on_dsm_detach_callback function, Datum arg);
4444
extern void cancel_on_dsm_detach(dsm_segment *seg,
4545
on_dsm_detach_callback function, Datum arg);
46+
extern void reset_on_dsm_detach(void);
4647

4748
#endif /* DSM_H */

0 commit comments

Comments
 (0)