Avoid cache stampede on std schema
The section loading the std schema now uses a lock to avoid the
situation where multiple simultaneous connections are all introspecting
std.
#
+import asyncio
import collections
import logging
import re
@@ -76,6 +77,7 @@ class OutputDescriptor:
class Backend:
std_schema = None
+ std_schema_lock = asyncio.Lock()
def __init__(self, connection):
self.schema = None
@@ -90,6 +92,8 @@ class Backend:
async def getschema(self):
if self.schema is None:
cls = type(self)
+ if cls.std_schema is None:
+ async with self.std_schema_lock:
if cls.std_schema is None:
cls.std_schema = await self._intro_mech.readschema(
modules=s_std.STD_MODULES)
