Skip to content

Conversation

@ofir-frd
Copy link

Benchmark PR PrefectHQ#19651

Type: Corrupted (contains bugs)

Original PR Title: Add memory safeguards to event persister service
Original PR Description: ## Summary

  • Add bounded queue (default 50,000 max) with backpressure - new events are dropped with a warning when queue is full
  • Add retry limit (default 5) - events are dropped after consecutive flush failures instead of infinite retry
  • Add flush lock to prevent concurrent flushes from message handler and periodic flush task
  • Add queue capacity monitoring - logs warning at 80% capacity

Related to PrefectHQ#18605

New settings
  • PREFECT_SERVER_SERVICES_EVENT_PERSISTER_QUEUE_MAX_SIZE (default: 50,000)
  • PREFECT_SERVER_SERVICES_EVENT_PERSISTER_MAX_FLUSH_RETRIES (default: 5)
Problem

The event persister could experience unbounded memory growth under certain failure conditions:

  1. Unbounded queue - If events arrive faster than they can be flushed, or if the database is unavailable, the queue grows without limit
  2. Infinite retry on flush failure - When write_events fails, events are restored to the queue and retried indefinitely
  3. No concurrent flush protection - Both message_handler and flush_periodically could trigger flush() simultaneously

🤖 Generated with Claude Code
Original PR URL: PrefectHQ#19651

Compliance Violation

  • Rule: Create Reproduction Scripts Before Fixing Issues
  • Language: Python
  • File: tests/events/server/storage/test_event_persister.py

desertaxle and others added 4 commits December 5, 2025 09:03
This PR adds safeguards to prevent unbounded memory growth in the event
persister under failure conditions:

- Add bounded queue (default 50,000 max) with backpressure - new events
  are dropped with a warning when queue is full
- Add retry limit (default 5) - events are dropped after consecutive
  flush failures instead of infinite retry
- Add flush lock to prevent concurrent flushes from message handler and
  periodic flush task
- Add queue capacity monitoring - logs warning at 80% capacity

New settings:
- `PREFECT_SERVER_SERVICES_EVENT_PERSISTER_QUEUE_MAX_SIZE`
- `PREFECT_SERVER_SERVICES_EVENT_PERSISTER_MAX_FLUSH_RETRIES`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Remove unnecessary validation_alias from queue_max_size and
  max_flush_retries (only needed for backward compatibility)
- Add src/prefect/settings/AGENTS.md documenting settings patterns
- Use settings object instead of legacy PREFECT_* constants in trim()
- Use logger format string instead of f-string

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants