diff --git a/modal/sandbox.py b/modal/sandbox.py index 2655ab4a6..ac73d29d5 100644 --- a/modal/sandbox.py +++ b/modal/sandbox.py @@ -19,7 +19,7 @@ from ._object import _get_environment_name, _Object from ._resolver import Resolver from ._resources import convert_fn_config_to_resources_config -from ._utils.async_utils import synchronize_api +from ._utils.async_utils import TaskContext, synchronize_api from ._utils.deprecation import deprecation_error from ._utils.grpc_utils import retry_transient_errors from ._utils.mount_utils import validate_network_file_systems, validate_volumes @@ -517,9 +517,8 @@ async def exec( raise InvalidError(f"workdir must be an absolute path, got: {workdir}") # Force secret resolution so we can pass the secret IDs to the backend. - # TODO should we parallelize this? - for secret in secrets: - await secret.hydrate(client=self._client) + secret_coros = [secret.hydrate(client=self._client) for secret in secrets] + await TaskContext.gather(*secret_coros) task_id = await self._get_task_id() req = api_pb2.ContainerExecRequest(