Skip to content

Commit 14d7d61

Browse files
author
Valeriy Zainullin
committed
Check collector has started in pg_wait_sampling_reset_profile.
The worker might have not started yet or it may never start, because its registration was cancelled due to worker limit. This commit adds a check for NULL value of pgws_collector_hdr->latch. The previous usage in pg_wait_sampling.c has such a check, we should do the same here.
1 parent fafeda0 commit 14d7d61

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pg_wait_sampling.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
808808
{
809809
LOCKTAG collectorTag;
810810

811+
/*
812+
* This also guards against the case when the
813+
* extension was not loaded at all, but this
814+
* function was called. pgws_collector_hdr is
815+
* NULL in this case.
816+
*/
811817
check_shmem();
812818

813819
pgws_init_lock_tag(&queueTag, PGWS_QUEUE_LOCK);
@@ -819,6 +825,18 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
819825
pgws_collector_hdr->request = PROFILE_RESET;
820826
LockRelease(&collectorTag, ExclusiveLock, false);
821827

828+
/* The collector may have not started yet (it'd be a
829+
* race condition with background worker startup to
830+
* use latch without a check here).
831+
* Or worse, registration of the worker might have been
832+
* denied, if there are too many workers already.
833+
* This is why we cannot wait for its start with a while
834+
* loop.
835+
*/
836+
if (!pgws_collector_hdr->latch)
837+
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
838+
errmsg("pg_wait_sampling collector wasn't started")));
839+
822840
SetLatch(pgws_collector_hdr->latch);
823841

824842
LockRelease(&queueTag, ExclusiveLock, false);

0 commit comments

Comments
 (0)