Accept invalidation messages in InitializeSessionUserId().
authorThomas Munro <tmunro@postgresql.org>
Fri, 13 Jul 2018 04:12:03 +0000 (16:12 +1200)
committerThomas Munro <tmunro@postgresql.org>
Fri, 13 Jul 2018 04:19:15 +0000 (16:19 +1200)
If the authentication method modified the system catalogs through a
separate database connection (say, to create a new role on the fly),
make sure syscache sees the changes before we try to find the user.

Author: Thomas Munro
Reviewed-by: Tom Lane, Andres Freund
Discussion: https://postgr.es/m/CAEepm%3D3_h0_cgmz5PMyab4xk_OFrg6G5VCN%3DnF4chFXM9iFOqA%40mail.gmail.com

src/backend/utils/init/miscinit.c

index 4bb28938c27b73a90096521f8ad0cbe96dae72eb..865119d272935959f666f234b7d2170dc504f437 100644 (file)
@@ -48,6 +48,7 @@
 #include "storage/procarray.h"
 #include "utils/builtins.h"
 #include "utils/guc.h"
+#include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/pidfile.h"
 #include "utils/syscache.h"
@@ -594,6 +595,13 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
    /* call only once */
    AssertState(!OidIsValid(AuthenticatedUserId));
 
+   /*
+    * Make sure syscache entries are flushed for recent catalog changes.
+    * This allows us to find roles that were created on-the-fly during
+    * authentication.
+    */
+   AcceptInvalidationMessages();
+
    if (rolename != NULL)
    {
        roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(rolename));