Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check collector has started in pg_wait_sampling_reset_profile.#100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
valeriy-zainullin wants to merge1 commit intopostgrespro:master
base:master
Choose a base branch
Loading
fromvaleriy-zainullin:master

Conversation

valeriy-zainullin
Copy link

@valeriy-zainullinvaleriy-zainullin commentedJun 19, 2025
edited
Loading

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.

@valeriy-zainullinvaleriy-zainullinforce-pushed themaster branch 2 times, most recently from392b87c to18088ddCompareJune 19, 2025 15:33
@valeriy-zainullinvaleriy-zainullin changed the titleCheck worker has started in pg_wait_sampling_reset_profile.Check collector has started in pg_wait_sampling_reset_profile.Jun 19, 2025
@valeriy-zainullin
Copy link
Author

Воспроизведение. Можно запускать в любой директории, создается временный докер-контейнер.

#!/bin/bashsudo docker run --rm -i ubuntu:24.04 bash<<"EOF"set -xeapt-get updateapt-get install -y \  git build-essential pkg-config libicu-dev libipc-run-perl \  flex bison libreadline-dev libz-dev gettext libperl-devgit clone -b REL_17_5 --depth 1 https://github.com/postgres/postgrescd postgresgit clone https://github.com/postgrespro/pg_wait_sampling contrib/pg_wait_samplingmkdir contrib/pgws_reproducecat - > contrib/pgws_reproduce/Makefile <<"_EOF"MODULE_big = pgws_reproduceOBJS = main.oEXTENSION = pgws_reproduceREGRESS =subdir = contrib/pgws_reproducetop_builddir = ../..include $(top_builddir)/src/Makefile.globalinclude $(top_srcdir)/contrib/contrib-global.mk_EOFcat - > contrib/pgws_reproduce/pgws_reproduce.control <<"_EOF" pg_wait_sampling extensioncomment = 'reproduce bug'default_version = '1'module_pathname = '$libdir/pgws_reproduce'relocatable = true_EOFcat - > contrib/pgws_reproduce/main.c <<"_EOF"#include "postgres.h"#include "postmaster/bgworker.h"#include "fmgr.h"#include <sched.h> /* Only works on linux. */PG_MODULE_MAGIC;void pgws_reproduce_worker_main(Datum main_arg);void _PG_init(void);void pgws_reproduce_worker_main(Datum main_arg) {  while (true) {    sched_yield();  }}void _PG_init(void) {  /* Default limit of workers is 8. */  for (int i = 0; i < 32; ++i) {    BackgroundWorker worker;    memset(&worker, 0, sizeof(worker));    worker.bgw_restart_time = 1;    worker.bgw_flags = BGWORKER_SHMEM_ACCESS;    snprintf(worker.bgw_library_name, BGW_MAXLEN, "pgws_reproduce");    snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(pgws_reproduce_worker_main));    worker.bgw_main_arg = (Datum) 0;    RegisterBackgroundWorker(&worker);  }}_EOFgrep -v '$(recurse' contrib/Makefile > output.txtmv output.txt contrib/Makefileecho 'SUBDIRS += pg_wait_sampling pgws_reproduce' >> contrib/Makefileecho -e '$(recurse)\n$(recurse_always)' >> contrib/MakefileCFLAGS='-ggdb -O0 -g' ./configure -q \  --enable-cassert --enable-tap-tests --enable-nls \  --with-icu --with-perl --prefix=$(pwd)/installmake -s -j$(nproc) world-binmake -s -j$(nproc) install-world-binuseradd postgreschown -R postgres .cd installsu postgres -c 'bin/initdb -D data'su postgres -c "echo \"shared_preload_libraries = 'pgws_reproduce, pg_wait_sampling'\" > data/postgresql.conf"su postgres -c 'bin/pg_ctl -D data -l logfile start' || (cat logfile; exit 1)cd ..su postgres -c 'make -C contrib/pg_wait_sampling installcheck' || (grep '(PID ' install/logfile; exit 2)cat install/logfileEOF

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, weshould do the same here.
* extension was not loaded at all, but this
* function was called. pgws_collector_hdr is
* NULL in this case.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think this it needed since comment forcheck_shmem is clear enough. It's also strange to have such comment only inreset_profile but not inpg_wait_sampling_get_history, for example

@@ -819,6 +825,18 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
pgws_collector_hdr->request = PROFILE_RESET;
LockRelease(&collectorTag, ExclusiveLock, false);

/* The collector may have not started yet (it'd be a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please, start a comment with an empty line, such as

/* * The collector may not have started yet...

* denied, if there are too many workers already.
* This is why we cannot wait for its start with a while
* loop.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe we can change this comment to be less verbose. Something like

Check that the collector was started to avoid NULL dereference

You could also add the same comment to receive array since it makes the same check

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@MedvecrabMedvecrabMedvecrab requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@valeriy-zainullin@Medvecrab

[8]ページ先頭

©2009-2025 Movatter.jp