Skip to content

Conversation

@muzahidul-opti
Copy link
Contributor

@muzahidul-opti muzahidul-opti commented Jan 12, 2026

Summary

Key Changes

  1. Elimination of Blocking Synchronization
    Removed DispatchGroup.wait(): Replaced the blocking synchronization used during network requests with non-blocking asynchronous completion handlers. This ensures that the serial queue threads are not held idle while waiting for I/O.
    Non-Blocking close(): Updated DefaultEventDispatcher.close() to use a timed wait on a DispatchGroup. This ensures a graceful shutdown by waiting for pending flushes without risk of hanging the application indefinitely (includes a 10-second safety timeout).
  2. Asynchronous Retry Strategy
    Exponential Backoff: Introduced a formal retry strategy using DispatchQueue.asyncAfter. This replaces the previous "tight-loop" retry behavior (where failed batches were retried immediately) with a non-blocking delay sequence (200ms, 400ms, 800ms).
    RetryStrategy Utility: Added a centralized RetryStrategy class to ensure consistent backoff logic across the SDK.
  3. State Management
    isFlushing Flag: Added state tracking to prevent multiple concurrent flush operations from running on the same dispatcher instance, improving thread safety and resource management.

Test plan

Issues

muzahidul-opti and others added 3 commits January 12, 2026 15:01
Implemented synchronous blocking retry strategy with exponential backoff for both DefaultEventDispatcher and OdpEventManager:

- Per-batch retry: Each batch gets up to 3 attempts with exponential backoff delays (200ms, 400ms, 800ms)
- Global failure counter: Tracks consecutive batch failures across all batches in a flush
- Blocking approach: Uses Thread.sleep() for delays and notify.wait() for synchronous operations
- Reachability fix: Moved updateNumContiguousFails() outside retry loop to prevent premature network blocking
- ODP error handling: Differentiates recoverable errors (retry) vs non-recoverable errors (discard)
- JSON determinism: Added .sortedKeys to JSONEncoder for consistent test assertions
- OdpConfig fix: Made update() synchronous to prevent race conditions

Added comprehensive test suites:
- OdpEventManagerRetryTests: 13 tests covering retry scenarios, error handling, and timing
- EventDispatcherRetryTests: Tests for DefaultEventDispatcher retry logic
- RetryStrategyTests: Unit tests for exponential backoff calculation
- Updated existing tests to match new retry behavior expectations

All tests passing: OdpEventManagerRetryTests (13/13), EventDispatcherTests_Batch (27/27)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@muzahidul-opti muzahidul-opti force-pushed the update-event-retry-strategy branch from 219f4ef to 83b0c5d Compare January 12, 2026 14:13
@muzahidul-opti muzahidul-opti marked this pull request as ready for review January 12, 2026 15:55
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a major rewrite and I hope it's fully tested with network failure cases against deadlock/livelock.
Other than that, all looks good to me! A couple of nits to clean up.

guard let batchEvent = batchedEvent else {
// discard an invalid event that causes batching failure
// - if an invalid event is found while batching, it batches all the valid ones before the invalid one and sends it out.
// - when trying to batch next, it finds the invalid one at the header. It discards // Invalid event - discard and continue with next batch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - comment format

Comment on lines +101 to +104

// if eventsBatched.count == 1 {
// return (1, first)
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intention to clean it up?

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