Skip to content

Commit

Permalink
Prevent recursion in invalidation processing
Browse files Browse the repository at this point in the history
This patch prevents recursing into the cache invalidation code.
Since this code's result is dependent on the transaction snapshot,
processing it multiple times recursively won't change the result.

Fixes #1486
  • Loading branch information
cevian committed Oct 25, 2019
1 parent 267451f commit f82d837
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ ts_extension_schema_name(void)
bool
ts_extension_invalidate(Oid relid)
{
static bool in_recursion = false;
bool invalidate_all = false;

/* Since the state of the extension is determined by the snapshot of the transaction there
* is no point processing recursive calls as the outer call will always set the correct state.
* This also prevents deep recursion during `AcceptInvalidationMessages`.
*/
if (in_recursion)
return false;

in_recursion = true;

switch (extstate)
{
case EXTENSION_STATE_NOT_INSTALLED:
Expand All @@ -207,7 +219,7 @@ ts_extension_invalidate(Oid relid)
case EXTENSION_STATE_TRANSITIONING:
/* Has the create/drop extension finished? */
extension_update_state();
return false;
break;
case EXTENSION_STATE_CREATED:

/*
Expand All @@ -224,14 +236,16 @@ ts_extension_invalidate(Oid relid)
* note this state may be UNKNOWN but should be
* conservative
*/
return true;
invalidate_all = true;
}
}
return false;
break;
default:
elog(ERROR, "unknown state: %d", extstate);
return false;
break;
}
in_recursion = false;
return invalidate_all;
}

bool
Expand Down

0 comments on commit f82d837

Please sign in to comment.