Summary:
Background Worker Error Handling Fix:
The previous implementation faced critical failures due to two main issues:
1. The background worker encountered stack overflow due to large expired_entries being allocated on the stack, causing SPI failures due to multiple calls. This has been fixed by using palloc for memory allocation instead.
2. The function YbGetPgssNormalizedQueryText() failed for queries exceeding YB_QD_MAX_PGSS_QUERY_LEN, as it performed a memcpy that wrote beyond the allocated buffer. This has been corrected to handle larger queries properly.
**Stack Overflow Risk**:
- Converted stack-allocated variables to heap allocation
- Reduced stack memory consumption
- Mitigated risk of stack overflow during error scenarios
**Error Handling Improvement**:
- Implemented PG_TRY()/PG_CATCH() blocks
- Prevented infinite error loops
- Enabled controlled error interception and logging
Jira: DB-14378
Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestYbQueryDiagnostics#testComplexQuery'
Reviewers: asaha
Reviewed By: asaha
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D40499