Skip to content

Commit 741b84e

Browse files
committed
Reproduce debug_query_string==NULL on parallel workers.
Certain background workers initiate parallel queries while debug_query_string==NULL, at which point they attempted strlen(NULL) and died to SIGSEGV. Older debug_query_string observers allow NULL, so do likewise in these newer ones. Back-patch to v11, where commit 7de4a1b introduced the first of these. Discussion: https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
1 parent 25b587f commit 741b84e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
13411341
BTLeader *btleader = (BTLeader *) palloc0(sizeof(BTLeader));
13421342
BufferUsage *bufferusage;
13431343
bool leaderparticipates = true;
1344-
char *sharedquery;
13451344
int querylen;
13461345

13471346
#ifdef DISABLE_LEADER_PARTICIPATION
@@ -1404,9 +1403,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
14041403
shm_toc_estimate_keys(&pcxt->estimator, 1);
14051404

14061405
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
1407-
querylen = strlen(debug_query_string);
1408-
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
1409-
shm_toc_estimate_keys(&pcxt->estimator, 1);
1406+
if (debug_query_string)
1407+
{
1408+
querylen = strlen(debug_query_string);
1409+
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
1410+
shm_toc_estimate_keys(&pcxt->estimator, 1);
1411+
}
1412+
else
1413+
querylen = 0; /* keep compiler quiet */
14101414

14111415
/* Everyone's had a chance to ask for space, so now create the DSM */
14121416
InitializeParallelDSM(pcxt);
@@ -1470,9 +1474,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
14701474
}
14711475

14721476
/* Store query string for workers */
1473-
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
1474-
memcpy(sharedquery, debug_query_string, querylen + 1);
1475-
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
1477+
if (debug_query_string)
1478+
{
1479+
char *sharedquery;
1480+
1481+
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
1482+
memcpy(sharedquery, debug_query_string, querylen + 1);
1483+
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
1484+
}
14761485

14771486
/* Allocate space for each worker's BufferUsage; no need to initialize */
14781487
bufferusage = shm_toc_allocate(pcxt->toc,
@@ -1669,7 +1678,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
16691678
#endif /* BTREE_BUILD_STATS */
16701679

16711680
/* Set debug_query_string for individual workers first */
1672-
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, false);
1681+
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
16731682
debug_query_string = sharedquery;
16741683

16751684
/* Report the query string from leader */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy