Re: Refactoring postmaster's code to cleanup after child exit
Heikki Linnakangas <hlinnaka@iki.fi>
On 09/12/2024 14:47, Tomas Vondra wrote: > On 12/9/24 13:30, Heikki Linnakangas wrote: >> On 09/12/2024 01:12, Tomas Vondra wrote: >>> On 11/14/24 15:13, Heikki Linnakangas wrote: >>>> On 09/10/2024 23:40, Heikki Linnakangas wrote: >>>>> I pushed the first three patches, with the new test and one of the >>>>> small >>>>> refactoring patches. Thanks for all the comments so far! Here is a new >>>>> version of the remaining patches. >>>>> >>> Hi, the TAP test 001_connection_limits.pl introduced by 6a1d0d470e84 >>> seems to have problems with valgrind :-( I reliably get this failure: >> >> How exactly do you run the test with valgrind? What platform? >> > > It failed for me on both amd64 (Fedora 41) and rpi5 32/64-bit (Debian). > >> It works for me, with this: >> >> (cd build && ninja && rm -rf tmp_install && meson test --suite setup && >> valgrind --leak-check=no --gen-suppressions=all --suppressions=/home/ >> heikki/git-sandbox/postgresql/src/tools/valgrind.supp --time-stamp=yes >> --error-markers=VALGRINDERROR-BEGIN,VALGRINDERROR-END --log-file=$HOME/ >> pg-valgrind/%p.log --trace-children=yes meson test --suite postmaster ) >> > > I have a patch that tweaks pg_ctl/pg_regress to execute valgrind, so I > just do > > ./configure --enable-debug --prefix=/home/user/builds/master > --enable-depend --enable-cassert --enable-tap-tests CPPFLAGS="-O0 -ggdb3 > -DUSE_VALGRIND" > > and then the usual "make check" or whatever. > > The patch has a hardcoded path to the .supp file, and places the > valgrind log into /tmp. It has worked for me fine up until that commit, > and it still seems to be working in every other test directory. Ok, I was able to reproduce this with that setup. Unsurprisingly, it's a timing issue. It can be reproduced without valgrind by adding this delay: diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 289059435a9..1eb6bad72ca 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -583,6 +583,7 @@ errfinish(const char *filename, int lineno, const char *funcname) * FATAL termination. The postmaster may or may not consider this * worthy of panic, depending on which subprocess returns it. */ + sleep(1); proc_exit(1); } The test opens a connection that is expected to fail with the "remaining connection slots are reserved for roles with the SUPERUSER attribute" error. Right after that, it opens a new connection as superuser, and expects it to succeed. But if the previous backend hasn't exited yet, the new connection fails with "too many clients already". Not sure how to fix this. A small sleep in the test would work, but in principle there's no delay that's guaranteed to be enough. A more robust solution would be to run a "select count(*) from pg_stat_activity" and wait until the number of connections are what's expected. I'll try that and see how complicated that gets.. -- Heikki Linnakangas Neon (https://neon.tech)
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix test name and username used in failed connection attempts
- 2a943afcff44 18.0 landed
-
tests: Don't fail due to high default timeout in postmaster/003_start_stop
- b48832cddbf5 18.0 landed
-
tests: Fix race condition in postmaster/002_connection_limits
- 71d1ed6fe129 18.0 landed
-
Pass MyPMChildSlot as an explicit argument to child process
- 5b007868577a 18.0 landed
-
Assign a child slot to every postmaster child process
- a78af0427015 18.0 landed
-
Kill dead-end children when there's nothing else left
- bb861414fea3 18.0 landed
-
Replace postmaster.c's own backend type codes with BackendType
- 18d67a8d7d30 18.0 landed
-
Use an shmem_exit callback to remove backend from PMChildFlags on exit
- 2bbc261ddbdf 18.0 landed
-
Add test for dead-end backends
- 85ec945b7880 18.0 landed
-
Add test for connection limits
- 6a1d0d470e84 18.0 landed
-
Fix garbled process name on backend crash
- 56d23855c864 18.0 landed
-
Consolidate postmaster code to launch background processes
- 3354f85284dc 18.0 landed
-
Fix comment on processes being kept over a restart
- a79ed10e6c6b 18.0 landed
-
Refactor code to handle death of a backend or bgworker in postmaster
- 28a520c0b773 18.0 landed
-
Make BackgroundWorkerList doubly-linked
- b43100fa71d7 18.0 landed
-
Minor refactoring of assign_backendlist_entry()
- 63bef4df975c 18.0 landed
-
Fix outdated comment; all running bgworkers are in BackendList
- ef4c35b4166e 18.0 landed
-
Allow building with MSVC and Strawberry perl
- 341f4e002d46 16.0 cited
-
Fix rare failure in LDAP tests.
- f44b9b625bed 14.0 cited
-
Allow notifications to bgworkers without database connections.
- 8a02b3d732cf 9.6.0 cited