fix(storage): fixing flushing and finalization in buffered upload of async client by shubham-up-47 · Pull Request #15572 · googleapis/google-cloud-cpp

This PR refactors AsyncWriterConnectionBuffered to fix critical bugs in its resume and finalization logic, which were discovered while updating integration tests where a final Flush was not happening during finalization, that time a temporary fix was done. These changes are totally inspired by the PR #15114 making the component significantly more reliable.

The original implementation was just calling Write() during Flush() and contained subtle flaws in its state machine when handling a Finalize() failure. This could lead to incorrect state transitions during a resume, or deadlocks where pending Flush calls would hang indefinitely during race conditions with SetFinalized. The fix introduces a distinct implementation for Flush() with its own promise queue to ensure a reliable completion signal. To correct the resume behavior, OnFinalize is modified to preserve the finalizing_ state, and OnResume is updated to use the new connection immediately, preventing incorrect retries. The idempotency guard in SetFinalized now correctly drains the flush queue to prevent hangs.

This change is Reviewable