Skip to content

Commit ab3b4ac

Browse files
authored
Remove idx_offset optimization from clientauth. (#295)
There was a math bug with this optimization that caused incoming connections to occassionally be missed by a worker. This optimization doesn't seem necessary and makes the code harder to understand and maintain, so just get rid of it. Update a TAP test for postgres 4f7f7b0 to pass CI on master.
1 parent aa9512d commit ab3b4ac

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/clientauth.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,6 @@ clientauth_launcher_main(Datum arg)
369369
{
370370
int bgw_idx = DatumGetInt32(arg);
371371

372-
/* Keeps track of which of its entries the worker will look at first. */
373-
int idx_offset = 0;
374-
375372
/* Establish signal handlers before unblocking signals */
376373
pqsignal(SIGHUP, clientauth_sighup);
377374
pqsignal(SIGTERM, die);
@@ -414,18 +411,13 @@ clientauth_launcher_main(Datum arg)
414411

415412
LWLockAcquire(clientauth_ss->lock, LW_SHARED);
416413

417-
/*
418-
* Check if this worker's assigned entries need processing.
419-
* idx_offset helps the worker pick up each entry more evenly
420-
* rather than always picking the first entry if it's occupied.
421-
*/
422-
for (int i = bgw_idx + idx_offset; i < CLIENT_AUTH_MAX_PENDING_ENTRIES + idx_offset; i += clientauth_num_parallel_workers)
414+
/* Check if this worker's assigned entries need processing. */
415+
for (int i = bgw_idx; i < CLIENT_AUTH_MAX_PENDING_ENTRIES; i += clientauth_num_parallel_workers)
423416
{
424-
idx = i % CLIENT_AUTH_MAX_PENDING_ENTRIES;
417+
idx = i;
425418
if (!clientauth_ss->requests[idx].done_processing)
426419
{
427420
need_to_wake = true;
428-
idx_offset = (idx_offset + clientauth_num_parallel_workers) % CLIENT_AUTH_MAX_PENDING_ENTRIES;
429421
break;
430422
}
431423
}

test/t/003_pg_tle_no_pu_hook_until_create.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
my ($stdout, $stderr);
3333

3434
$node->psql($testdb, "CREATE EXTENSION does_not_exist", stdout => \$stdout, stderr => \$stderr);
35-
like ($stderr, qr/[cC]ould not open extension control file/, 'Extension should not be found');
35+
like ($stderr, qr/[cC]ould not open extension control file|extension "does_not_exist" is not available/, 'Extension should not be found');
3636

3737
$node->psql($testdb, "CREATE EXTENSION pg_tle", stdout => \$stdout, stderr => \$stderr);
3838
like ($stderr, qr//, 'pg_tle creates successfully');
3939

4040
$node->psql($testdb, "CREATE EXTENSION does_not_exist", stdout => \$stdout, stderr => \$stderr);
41-
like ($stderr, qr/[cC]ould not open extension control file/, 'Extension should still not be found');
41+
like ($stderr, qr/[cC]ould not open extension control file|extension "does_not_exist" is not available/, 'Extension should still not be found');
4242

4343
$node->stop;
44-
done_testing();
44+
done_testing();

0 commit comments

Comments
 (0)