Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d85fc4b

Browse files
committed
Improve locking around InjectionPointRun()
As coded, an injection point could be loaded into the local cache without the LWLock InjectionPointLock taken, hence a point detached and re-attached concurrently of a point running calling InjectionPointRun() may finish by loading a callback it did no set initially. Based on all the cases discussed until now on the lists, it is fine to delay the lock release until the callback is run, so let's do that. While on it, remove a useless LWLockRelease() called before an error in InjectionPointAttach(). Per discussion with Heikki Linnakangas and Noah Misch. Discussion: https://postgr.es/m/e1ffb822-054e-4006-ac06-50532767f75b@iki.fi
1 parent 4a7f91b commit d85fc4b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/utils/misc/injection_point.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ InjectionPointAttach(const char *name,
234234
hash_search(InjectionPointHash, name,
235235
HASH_ENTER, &found);
236236
if (found)
237-
{
238-
LWLockRelease(InjectionPointLock);
239237
elog(ERROR, "injection point \"%s\" already defined", name);
240-
}
241238

242239
/* Save the entry */
243240
strlcpy(entry_by_name->name, name, sizeof(entry_by_name->name));
@@ -300,7 +297,6 @@ InjectionPointRun(const char *name)
300297
entry_by_name = (InjectionPointEntry *)
301298
hash_search(InjectionPointHash, name,
302299
HASH_FIND, &found);
303-
LWLockRelease(InjectionPointLock);
304300

305301
/*
306302
* If not found, do nothing and remove it from the local cache if it
@@ -309,6 +305,7 @@ InjectionPointRun(const char *name)
309305
if (!found)
310306
{
311307
injection_point_cache_remove(name);
308+
LWLockRelease(InjectionPointLock);
312309
return;
313310
}
314311

@@ -343,6 +340,9 @@ InjectionPointRun(const char *name)
343340

344341
/* Now loaded, so get it. */
345342
injection_callback = injection_point_cache_get(name, &private_data);
343+
344+
LWLockRelease(InjectionPointLock);
345+
346346
injection_callback(name, private_data);
347347
#else
348348
elog(ERROR, "Injection points are not supported by this build");

0 commit comments

Comments
 (0)