@@ -122,7 +122,7 @@ async def open_storage_instance(
122122 if not any ([name , alias , id ]):
123123 alias = self ._DEFAULT_STORAGE_ALIAS
124124
125- # Check cache
125+ # Check cache without lock first for performance.
126126 if cached_instance := self ._get_from_cache (
127127 cls ,
128128 id = id ,
@@ -132,14 +132,6 @@ async def open_storage_instance(
132132 ):
133133 return cached_instance
134134
135- # Check for conflicts between named and alias storages
136- self ._check_name_alias_conflict (
137- cls ,
138- name = name ,
139- alias = alias ,
140- storage_client_cache_key = storage_client_cache_key ,
141- )
142-
143135 # Validate storage name
144136 if name is not None :
145137 validate_storage_name (name )
@@ -151,7 +143,8 @@ async def open_storage_instance(
151143 self ._opener_locks [opener_lock_key ] = lock
152144
153145 async with lock :
154- # Another task could have created the storage while we were waiting for the lock - check if that happened
146+ # Another task could have created the storage while we were waiting for the lock - check if that
147+ # happened
155148 if cached_instance := self ._get_from_cache (
156149 cls ,
157150 id = id ,
@@ -161,7 +154,7 @@ async def open_storage_instance(
161154 ):
162155 return cached_instance
163156
164- # Re-check for conflicts between named and alias storages
157+ # Check for conflicts between named and alias storages
165158 self ._check_name_alias_conflict (
166159 cls ,
167160 name = name ,
@@ -179,6 +172,9 @@ async def open_storage_instance(
179172 instance_name = getattr (instance , 'name' , None )
180173
181174 # Cache the instance.
175+ # Note: No awaits in this section. All cache entries must be written
176+ # atomically to ensure pre-checks outside the lock see consistent state.
177+
182178 # Always cache by id.
183179 self ._cache .by_id [cls ][instance .id ][storage_client_cache_key ] = instance
184180
0 commit comments