Skip to content

GH-55790: [C++][FlightRPC][ODBC] - SQLCancel is unimplemented, ausing duplicate query submissions and a crash- #1⁠ (#167) - #55950

Open
RekTai wants to merge 1 commit into
apache:mainfrom
dremio:base-branch-gh-55790
Open

RekTai wants to merge 1 commit into
apache:mainfrom
dremio:base-branch-gh-55790

Conversation

@RekTai

@RekTai RekTai commented Dec 3, 2026 •

Copy link
Copy Markdown

Rationale for this change

SQLCancel was an unimplemented placeholder that unconditionally threw "SQLCancel is not implemented" (IM001), even though the underlying cancellation plumbing already existed. When Excel/Power BI try to cancel a long-running fetch and SQLCancel fails, they abandon the statement and resubmit the same query.

What changes are included in this PR?

  • entry_points.cc: SQLCancel now calls ODBCStatement::Cancel() and returns SQL_SUCCESS instead of throwing.
  • FlightStreamChunkBuffer: retains each DoGet stream's FlightStreamReader and adds Cancel(), which calls FlightStreamReader::Cancel() (gRPC TryCancel) before closing the queue, so Close() doesn't hang joining a producer thread blocked in Next().
  • FlightSqlResultSet::Cancel() now goes through the new FlightStreamChunkBuffer::Cancel() path.
  • FlightSqlStatement guards current_result_set_ with a mutex, since SQLCancel must be safe to call from a different thread than the one blocked in SQLExecute/SQLFetch.

This covers cancellation while fetching rows (the reported scenario). The initial query-execution RPC itself still can't be interrupted mid-flight -- Arrow's gRPC Flight transport doesn't expose a cancel hook for that unary call; that would need a separate transport-layer change.

Are these changes tested?

Yes. TestSQLCancelOnIdleStatement and TestSQLCancelDuringFetch, which failed (and crashed) before the fix, now pass -- tested against the mock server and manual verification through Excel.

Are there any user-facing changes?

No public API changes.

This PR contains a "Critical Fix". It fixes a crash (libc++abi terminating) caused by a stuck fetch thread with no way to be cancelled.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…causing duplicate query submissions and a crash- #1⁠ (#167)

### Rationale for this change

SQLCancel was an unimplemented placeholder that unconditionally threw "SQLCancel is not implemented" (IM001), even though the underlying cancellation plumbing already existed. When Excel/Power BI try to cancel a long-running fetch and SQLCancel fails, they abandon the statement and resubmit the same query.

### What changes are included in this PR?

* entry_points.cc: SQLCancel now calls ODBCStatement::Cancel() and returns SQL_SUCCESS instead of throwing.
* FlightStreamChunkBuffer: retains each DoGet stream's FlightStreamReader and adds Cancel(), which calls FlightStreamReader::Cancel() (gRPC TryCancel) before closing the queue, so Close() doesn't hang joining a producer thread blocked in Next().
* FlightSqlResultSet::Cancel() now goes through the new FlightStreamChunkBuffer::Cancel() path.
* FlightSqlStatement guards current_result_set_ with a mutex, since SQLCancel must be safe to call from a different thread than the one blocked in SQLExecute/SQLFetch.

This covers cancellation while fetching rows (the reported scenario). The initial query-execution RPC itself still can't be interrupted mid-flight -- Arrow's gRPC Flight transport doesn't expose a cancel hook for that unary call; that would need a separate transport-layer change.

### Are these changes tested?

Yes. TestSQLCancelOnIdleStatement and TestSQLCancelDuringFetch, which failed (and crashed) before the fix, now pass -- tested against the mock server and manual verification through Excel.

### Are there any user-facing changes?

No public API changes.

**This PR contains a "Critical Fix".** It fixes a crash (libc++abi terminating) caused by a stuck fetch thread with no way to be cancelled.

**PR code and description written by:**

- [x] Human
- [x] AI

**Reviewed before submission by:**

- [x] Human
- [ ] AI
- [ ] Not reviewed

* GitHub Issue: apache#55790
@alinaliBQ

Copy link
Copy Markdown
Collaborator

Comment for PR description:

  1. This PR contains a "Critical Fix". It fixes a crash (libc++abi terminating) caused by a stuck fetch thread with no way to be cancelled. I think it is not a critical fix because this is more like a missing feature. Leaving the final decision to Arrow maintainers though.

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1. LGTM.
Leaving this PR for other reviewers to take another look.

@RekTai

RekTai commented Dec 3, 2026

Copy link
Copy Markdown
Author

@lidavidm @kou This PR is ready for review, please have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][FlightRPC][ODBC] - SQLCancel is unimplemented, causing duplicate query submissions and a crash

2 participants