[#1472] fix(client): IlegalReferenceCountException for clientReadHandler.readShuffleData (#1536)
### What changes were proposed in this pull request?
Fix IllegalReferenceCountException issues when exceptions happened in clientReadHandler.readShuffleData().
### Why are the changes needed?
A follow-up PR for: https://github.com/apache/incubator-uniffle/pull/1522
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Existing UTs.
diff --git a/client/src/main/java/org/apache/uniffle/client/impl/ShuffleReadClientImpl.java b/client/src/main/java/org/apache/uniffle/client/impl/ShuffleReadClientImpl.java
index e1fbb9f..2831812 100644
--- a/client/src/main/java/org/apache/uniffle/client/impl/ShuffleReadClientImpl.java
+++ b/client/src/main/java/org/apache/uniffle/client/impl/ShuffleReadClientImpl.java
@@ -270,6 +270,10 @@
// because PlatformDependent.freeDirectBuffer can only release the ByteBuffer with cleaner.
if (sdr != null) {
sdr.release();
+ // We set sdr to null here to prevent IllegalReferenceCountException that could occur
+ // if sdr.release() is called multiple times in the close() method,
+ // when an exception is thrown by clientReadHandler.readShuffleData().
+ sdr = null;
}
sdr = clientReadHandler.readShuffleData();
readDataTime.addAndGet(System.currentTimeMillis() - start);