Add stack-safe loop execution to async framework

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Unknown
    • 5.7.0
    • Affects Version/s: None
    • Component/s: Async
    • None
    • None
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Async loops (thenRunDoWhileLoop) can crash with StackOverflowError when loop iterations complete synchronously on the same thread. In same-thread completion scenarios, the callback for the next iteration is invoked on the same stack, causing recursive stack growth which can lead to the stack overflow.

      Example call stack growth (simplified)

      LoopingCallback.onResult() [iteration 1]
        → body.run(this)
          → body completes synchronously
            → LoopingCallback.onResult() [iteration 2]
              → body.run(this)
                → body completes synchronously
                  → LoopingCallback.onResult() [iteration 3]
                    → ...
                      → StackOverflowError at N iterations

      Acceptance Criteria

      • Stack depth remains constant with iteration count (no recursion).
      • Behavior remains unchanged for iterations completing asynchronously on other threads.
      • Implement thenRunWhileLoop with equivalent stack-safety guarantees.

            Assignee:
            Slav Babanin
            Reporter:
            Slav Babanin
            Almas Abdrazak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: