Skip to content

perf(cloud-ai): AWS Rekognition blocks the event loop on 14 synchronous boto3 calls #1204

Description

@groupthinking

Problem

AWSRekognition (src/youtube_extension/integrations/cloud_ai/providers/aws_rekognition.py) issues 14 synchronous boto3 calls directly inside async def methods. boto3 has no async API, so every one of these blocks the event loop for a full network round-trip.

Method Blocking boto3 calls
_test_connection describe_collection
analyze_image detect_labels, detect_faces, detect_text, detect_moderation_labels
get_service_status describe_collection
_start_video_analysis start_label_detection, start_face_detection, start_text_detection, start_content_moderation
_wait_for_job_completion get_label_detection, get_face_detection, get_text_detection, get_content_moderation

_wait_for_job_completion is the worst case — it polls on a 5s interval up to max_wait_time (default 600s), so a single video analysis can stall the loop up to 120 times.

_prepare_image_input additionally does open(image_url, 'rb').read() on the loop for local files (the sibling http(s) branch already correctly uses httpx.AsyncClient).

Reachability evidence

youtube_extension.integrations.cloud_ai.providers.aws_rekognition is in the transitive import closure of the primary production entrypoint (youtube_extension.main:app, root Dockerfile:93):

  • backend/cloud_ai_routes.py:89,141 maps the aws_rekognition provider
  • integrations/cloud_ai/integrator.py:297-298 imports and constructs AWSRekognition
  • main.py:171 mounts cloud_ai_routes

Acceptance criteria

  • All 14 boto3 calls dispatch through await asyncio.to_thread(...)
  • The local-file read in _prepare_image_input runs off the loop
  • All 89 pre-existing tests pass without modification
  • New tests prove the loop stays responsive, and fail against the pre-change code
  • ruff at parity with main

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions