You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "eric-wang-1990 (via GitHub)" <gi...@apache.org> on 2026/03/24 08:45:23 UTC

[PR] fix(csharp/client): clear cached record batch in Read() to prevent stale data on exception [arrow-adbc]

eric-wang-1990 opened a new pull request, #4133:
URL: https://github.com/apache/arrow-adbc/pull/4133

   ## Summary
   
   - Fix infinite loop in `AdbcDataReader.Read()` when `ReadNextRecordBatchAsync()` throws mid-stream
   - Clear `this.recordBatch` before calling `.Result` so retried `Read()` calls don't re-serve stale rows
   
   ## Problem
   
   When `ReadNextRecordBatchAsync().Result` throws (e.g., server error mid-stream), `AdbcDataReader.Read()` does not clear `this.recordBatch`. If the caller retries `Read()`:
   
   1. `recordBatch` is still non-null (from the last successful fetch)
   2. `currentRowInRecordBatch` was reset to 0 by `ReadNextRecordBatchAsync()` before it threw
   3. `Read()` returns `true` and the caller re-reads all stale rows
   4. When the stale batch is exhausted, `ReadNextRecordBatchAsync()` throws again
   5. Infinite loop: throw → re-read stale batch → throw → re-read stale batch
   
   This was observed with Power BI Desktop, which retries `Read()` after exceptions, causing it to hang forever with a loading spinner instead of surfacing the error to the user.
   
   ## Fix
   
   Set `this.recordBatch = null` before calling `.Result`. On exception, the batch is already cleared, so retry calls fall through to fetch again (which re-throws the error).
   
   ## Test plan
   
   - [ ] Verified with Power BI Desktop: error now surfaces correctly instead of infinite hang
   - [ ] Existing unit tests pass
   - [ ] Manual test: stop SQL warehouse mid-query → PBI shows error dialog instead of spinner
   
   This pull request was AI-assisted by Isaac.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(csharp/src/Client): clear cached record batch in Read() to prevent stale data on exception [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #4133:
URL: https://github.com/apache/arrow-adbc/pull/4133#discussion_r2981147112


##########
csharp/src/Client/AdbcDataReader.cs:
##########
@@ -335,6 +335,11 @@ public override bool Read()
                 return true;
             }
 
+            // Clear the previous batch before fetching the next one.
+            // If ReadNextRecordBatchAsync throws (e.g. server error mid-stream),
+            // callers that retry Read() must not re-read stale rows from the
+            // old batch — they must see the exception again immediately.
+            this.recordBatch = null;

Review Comment:
   It looks like there's a preexisting bug here where `this.recordBatch` never gets `Dispose`d. Could you add that to this PR?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(csharp/src/Client): clear cached record batch in Read() to prevent stale data on exception [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher merged PR #4133:
URL: https://github.com/apache/arrow-adbc/pull/4133


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(csharp/src/Client): clear cached record batch in Read() to prevent stale data on exception [arrow-adbc]

Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #4133:
URL: https://github.com/apache/arrow-adbc/pull/4133#discussion_r2981822932


##########
csharp/src/Client/AdbcDataReader.cs:
##########
@@ -335,6 +335,11 @@ public override bool Read()
                 return true;
             }
 
+            // Clear the previous batch before fetching the next one.
+            // If ReadNextRecordBatchAsync throws (e.g. server error mid-stream),
+            // callers that retry Read() must not re-read stale rows from the
+            // old batch — they must see the exception again immediately.
+            this.recordBatch = null;

Review Comment:
   I don't think a caller should call `Read()` again if the previous call returned an error, but that doesn't mean we can't improve this code. Anyhow, I see a bunch of other small things that need fixing so I'll check in this change as-is and submit a followup PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org