Skip to content

Fix Redis client loop ownership in prefect-redis#22457

Draft
desertaxle wants to merge 3 commits into
mainfrom
codex/redis-client-loop-lifecycle
Draft

Fix Redis client loop ownership in prefect-redis#22457
desertaxle wants to merge 3 commits into
mainfrom
codex/redis-client-loop-lifecycle

Conversation

@desertaxle

@desertaxle desertaxle commented Jul 8, 2026

Copy link
Copy Markdown
Member

closes #22442

this PR fixes the prefect-redis async Redis client lifecycle by removing the process-global Redis client cache and making client ownership explicit.

Details

The previous cache could hold async Redis clients after their event loop had closed. That made cleanup depend on dead-loop socket teardown, which pushed the fix toward private redis-py and asyncio transport internals.

This changes the lifecycle contract instead:

  • get_async_redis_client() and async_redis_from_settings() now require a running event loop and return uncached clients.
  • managed_async_redis_client() creates a client and closes it before leaving the active loop.
  • Redis-backed messaging, event ordering, and concurrency lease storage no longer create Redis clients in synchronous constructors.
  • Redis consumers create a fresh managed client for each connection attempt, so reconnects no longer rely on clearing global cached clients.
  • Existing cache cleanup helpers remain as compatibility no-ops because there is no global client cache to clear.

@github-actions github-actions Bot added the bug Something isn't working label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prefect-redis: cached async Redis clients are never closed when their event loop ends → connection/FD leak in long-running services

1 participant