Techdebt: Lock VPC service collection to remove race condition (#7453)

This commit is contained in:
Bert Blommers 2024-03-10 11:38:42 +00:00 committed by GitHub
parent b923383039
commit d5042facb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import ipaddress import ipaddress
import json import json
import threading
import weakref import weakref
from collections import defaultdict from collections import defaultdict
from operator import itemgetter from operator import itemgetter
@ -82,6 +83,7 @@ IMPLEMENTED_ENDPOINT_SERVICES = [
] ]
MAX_NUMBER_OF_ENDPOINT_SERVICES_RESULTS = 1000 MAX_NUMBER_OF_ENDPOINT_SERVICES_RESULTS = 1000
DEFAULT_VPC_ENDPOINT_SERVICES: List[Dict[str, str]] = [] DEFAULT_VPC_ENDPOINT_SERVICES: List[Dict[str, str]] = []
ENDPOINT_SERVICE_COLLECTION_LOCK = threading.Lock()
class VPCEndPoint(TaggedEC2Resource, CloudFormationModel): class VPCEndPoint(TaggedEC2Resource, CloudFormationModel):
@ -773,6 +775,8 @@ class VPCBackend:
account_id: str, region: str account_id: str, region: str
) -> List[Dict[str, str]]: ) -> List[Dict[str, str]]:
"""Return list of default services using list of backends.""" """Return list of default services using list of backends."""
with ENDPOINT_SERVICE_COLLECTION_LOCK:
if DEFAULT_VPC_ENDPOINT_SERVICES: if DEFAULT_VPC_ENDPOINT_SERVICES:
return DEFAULT_VPC_ENDPOINT_SERVICES return DEFAULT_VPC_ENDPOINT_SERVICES