matanper opened a new issue, #70850:
URL: https://github.com/apache/doris/issues/70850

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Version
   
   master (`5f11f435e9`, after #69945 and #69996). Reproduced on a 
branch-4.1-based build with #69945, #69996 and #70676 applied.
   
   ### What's Wrong?
   
   When a Flight query fails, the result stream that carries the failure is 
treated as an early close. The early-close cancellation can then reach the 
other result BEs before the query's real error does, so clients reading those 
endpoints get `[CANCELLED] Arrow Flight stream closed before EOF` instead of 
the error that failed the query.
   
   The path, on master:
   
   1. `ArrowFlightBatchReaderBase::ReadNext` 
(`be/src/service/arrow_flight/arrow_flight_batch_reader.cpp:167-181`) calls 
`close(to_doris_status(status))` on **any** read error, including the result 
buffer reporting the query's own failure.
   2. `close()` (`arrow_flight_batch_reader.cpp:100-160`) cancels the local 
Arrow Flight buffers and then always calls `cancelFlightQuery` on the FEs. The 
RPC carries only the query id, not the reason.
   3. `FlightSqlQueryCancellation.cancel` 
(`fe/fe-core/src/main/java/org/apache/doris/arrowflight/FlightSqlQueryCancellation.java:150-162`)
 cancels the query on every BE of the route with `CANCELLED "Arrow Flight 
stream closed before EOF"`. It does not know that the query already failed.
   4. The coordinator's own cancellation with the real error runs 
independently. On each BE the first cancellation wins: the result buffer, 
`QueryContext::cancel`, and the Arrow Flight buffer cancel all keep the first 
status. If the early-close cancel arrives first, the real error is lost on that 
BE for good.
   
   With the parallel result sink, a query has an endpoint on each result BE. 
The failing BE's endpoint sees the real error locally first, so a client that 
reads that endpoint first triggers the race against every other endpoint.
   
   ### What You Expected?
   
   A stream that ends because its result buffer reports the query's own failure 
or cancellation should not be treated as an early close. The other endpoints 
should report the query's original error.
   
   A possible fix: on the BE, keep the local cleanup but skip the 
`cancelFlightQuery` call when the read error came from the result buffer's own 
status, i.e. the query has already failed or been cancelled and the coordinator 
propagates that status. Keep the FE call for a client close or cancel, an 
abandoned stream (destructor), a conversion error, and a transport failure.
   
   ### How to Reproduce?
   
   1 FE, 2 BEs, `enable_parallel_result_sink=true`.
   
   ```sql
   CREATE TABLE t2 (k BIGINT, v STRING) DISTRIBUTED BY HASH(k) BUCKETS 16 
PROPERTIES ("replication_num" = "1");
   INSERT INTO t2 SELECT number, cast(number AS STRING) FROM numbers("number" = 
"200000");
   ```
   
   Check that tablets are spread over both BEs, and note which BE holds `k = 
12345`. Then, through Flight SQL (e.g. ADBC):
   
   ```sql
   SELECT t.k, assert_true(t.k != 12345, 'boom 12345'), n.number
   FROM t2 t CROSS JOIN [broadcast] (SELECT number FROM numbers("number" = 
"1000")) n;
   ```
   
   Read the endpoint on the BE that holds `k = 12345` until it fails, then read 
the endpoint on the other BE.
   
   In 35 attempts:
   - The failing BE's endpoint returned the original error (`boom 12345`) every 
time.
   - The other endpoint returned `[CANCELLED] Arrow Flight stream closed before 
EOF` in 2 attempts, and the original error in 33.
   - In the 12 attempts whose BE logs were checked, the other BE received the 
`closed before EOF` cancellation before the original error in 10. So the race 
is usually lost on the server, and the client only sees it when it reads that 
endpoint's buffer after the wrong status lands.
   
   With the BE skipping `cancelFlightQuery` for result-buffer errors, both 
endpoints returned the original error in 32 of 32 attempts, and the other BE 
always received the original error first.
   
   ### Anything Else?
   
   Related: #69945, #69996, #70676 (which keeps the original error for a buffer 
cancelled before its schema fetch, but not for this race).
   
   We have a patch with BE unit tests and can open a PR.
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to