fix: remove pthread_mutex that causes self-deadlock on VLE queries#2433
Merged
jrgemignani merged 1 commit intoJun 9, 2026
Merged
Conversation
The pthread_mutex in manage_GRAPH_global_contexts() causes permanent self-deadlock when ereport(ERROR) triggers siglongjmp while the mutex is held, skipping pthread_mutex_unlock(). Any subsequent VLE query on the same backend connection hangs forever in pthread_mutex_lock() with __owner == own PID. The mutex was introduced in PR apache#1881 (fix for issue apache#1878) but is unnecessary: it protects a process-local static variable in PostgreSQL's single-threaded backend model where no concurrent access exists. The actual fix for apache#1878 was the Assert-to-runtime-check conversion and strndup defensive copy, which remain untouched.
There was a problem hiding this comment.
Pull request overview
This PR removes the pthread_mutex-based locking around the per-backend global graph-context list in age_global_graph.c to prevent permanent self-deadlock when PostgreSQL errors (ereport(ERROR) via siglongjmp, e.g., statement timeout/cancel/OOM) occur while the mutex is held during VLE-related cache operations.
Changes:
- Removed
#include <pthread.h>and the mutex-containingGRAPH_global_context_container. - Reverted the per-process context head back to a simple
static GRAPH_global_context *global_graph_contexts. - Removed all
pthread_mutex_lock()/pthread_mutex_unlock()calls from global-context management and lookup paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@crdv7 Please see the above Copilot message. edit nvm, this is pre-existing and needs to be addressed separately. |
jrgemignani
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remove
pthread_mutexfromage_global_graph.c— it causes permanent self-deadlock on VLE queries.ereport(ERROR)(statement timeout, query cancellation, OOM, etc.) triggerssiglongjmpwhich skipspthread_mutex_unlock(). The mutex remains locked, and every subsequent VLE query on the same backend hangs forever inpthread_mutex_lock()with__owner == own PID.Closes #2432
Analysis
The mutex was introduced in PR #1881 (fix for #1878). It is both unnecessary and harmful:
Unnecessary: The protected variable is a process-local
static— no concurrent access exists. The test failure in Flaky test age_global_graph fails on slow machines #1878 was a catalog-level race, already fixed by the Assert→runtime check andstrndupin the same PR. For cross-backend cache invalidation, PostgreSQL syscache usessinvalcallbacks, and PR VLE cache: replace snapshot invalidation with per-graph #2376 already uses lock-freepg_atomic_uint64version counters in shared memory for this.Harmful:
pthread_mutexis incompatible with PostgreSQL'sereport(ERROR)/siglongjmperror handling. Any ERROR during the mutex-held window permanently locks it. This is the only use ofpthreadin the entire AGE codebase.Changes
src/backend/utils/adt/age_global_graph.c(1 file, +13 −50):#include <pthread.h>GRAPH_global_context_containerstruct (withpthread_mutex_tfield)static GRAPH_global_context *global_graph_contexts = NULLpthread_mutex_lock/unlockcalls (20 references)The other fixes from PR #1881 (Assert→runtime check +
strndup) remain untouched.Verification
statement_timeout: no longer hangs after fix