sadikovi opened a new pull request, #60639:
URL: https://github.com/apache/spark/pull/60639

   ### What changes were proposed in this pull request?
   
   `TransportResponseHandler.handle` removes a `ChunkFetchSuccess`, 
`RpcResponse` or `MergedBlockMetaSuccess` request from its outstanding requests 
before it calls the success callback. This PR makes a throwing success callback 
fail its own request:
   
   - `TransportResponseHandler`: when `onSuccess` throws, call the request's 
`onFailure` with the same error, release the response body in `finally`, and 
rethrow the original error so the channel is still torn down and the other 
outstanding requests are failed. An `Exception` from `onFailure` is logged; an 
`Error` propagates.
   - `RetryingBlockTransferor`: with retries enabled 
(`spark.shuffle.io.maxRetries`, 3 by default), the block has already left the 
pending set when the parent's `onBlockTransferSuccess` throws, so a failure 
reported for it later was ignored. The listener now forwards 
`onBlockTransferFailure` for that block itself and rethrows; an error from that 
call is attached as suppressed.
   - `ShuffleBlockFetcherIterator`: a success callback can also throw after it 
has queued the block's `SuccessFetchResult`. The fetch listener now tracks the 
blocks delivered in each request and ignores a later failure for a delivered 
block, so a fetched block is neither turned into a `FetchFailedException` nor 
deferred and fetched again after a Netty OOM (which would return its rows 
twice). Related changes in the same listener:
     - The buffer reference is taken right before the result is queued, and 
released if queuing fails, so a throw earlier in the callback no longer leaks 
it.
     - When a failure for a delivered block is ignored, the request's blocks 
deferred after a Netty OOM are still enqueued.
   - The Javadoc of `BaseResponseCallback`, `ChunkReceivedCallback`, 
`RpcResponseCallback`, `MergedBlockMetaResponseCallback`, 
`BlockFetchingListener` and `BlockTransferListener` now says that a failure 
callback can follow a success callback that threw.
   
   ### Why are the changes needed?
   
   If a success callback throws, for example with an `OutOfMemoryError` in the 
Netty event loop, the exception reaches 
`TransportChannelHandler.exceptionCaught`, which fails the remaining 
outstanding requests and closes the channel. The request whose callback threw 
is no longer tracked, so neither the connection close nor the idle timeout ever 
fails it, and its caller waits forever. On the chunk fetch path the response 
body was also not released.
   
   For a shuffle fetch, the block never reaches `ShuffleBlockFetcherIterator`'s 
results queue, and the task blocks on `results.take()` indefinitely, with no 
`FetchFailedException` and no retry. This is the chunk and RPC counterpart of 
SPARK-57709, which fixed the same class of hang for stream callbacks.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. A shuffle fetch whose success callback throws now fails the task with a 
fetch failure instead of hanging it.
   
   ### How was this patch tested?
   
   New unit tests:
   - `TransportResponseHandlerSuite`: for chunk fetch, RPC and merged block 
meta responses, a `RuntimeException` or `OutOfMemoryError` from `onSuccess` is 
rethrown unchanged, `onFailure` receives the same error, the body is released 
and no request is left outstanding. When `onFailure` also throws, the original 
error is still rethrown and the body is still released.
   - `RetryingBlockTransferorSuite`: a throwing parent success callback reaches 
the parent as a failure exactly once and is rethrown 
(`testParentSuccessCallbackThrows`); when the parent's failure callback also 
throws, that error is attached as suppressed 
(`testParentSuccessAndFailureCallbacksThrow`).
   - `ShuffleBlockFetcherIteratorSuite`: a failure after a delivered result is 
ignored; a Netty OOM failure for a delivered block does not fetch it again; a 
failure for a block whose result was never queued still fails the fetch; and a 
success callback that throws before queuing does not take a buffer reference.
   
   Ran locally with JDK 21:
   ```
   build/sbt "network-common/testOnly *TransportResponseHandlerSuite" \
     "network-shuffle/testOnly *RetryingBlockTransferorSuite" \
     "core/testOnly *ShuffleBlockFetcherIteratorSuite"
   ```
   All pass. Without the `ShuffleBlockFetcherIterator` change, the three new 
iterator tests for a delivered block and for the buffer reference fail.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written 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: [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