Skip to content

Commit 25cf0e1

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 25cf0e1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pg_wait_sampling.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,18 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
819819
pgws_collector_hdr->request = PROFILE_RESET;
820820
LockRelease(&collectorTag, ExclusiveLock, false);
821821

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

824836
LockRelease(&queueTag, ExclusiveLock, false);

0 commit comments

Comments
 (0)