This is an automated email from the ASF dual-hosted git repository. zuston pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push: new 9bd93f234 [#2103] fix(server): Potential bytebuf offset race condition when flushing and getting data (#2104) 9bd93f234 is described below commit 9bd93f2341f5c6f7cd721ecbf882cba12e479f24 Author: zhengchenyu <zhengcheny...@163.com> AuthorDate: Tue Sep 10 19:14:48 2024 +0800 [#2103] fix(server): Potential bytebuf offset race condition when flushing and getting data (#2104) ### What changes were proposed in this pull request? When flush block and getInMemoryShuffleData occur together, may cause data reading errors. Because there may be two threads reading data at the same time, and the readIndex of ByteBuf will be inconsistent. So we should use duplicated when read bytes from ByteBuf. ### Why are the changes needed? Fix: #2103 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? unit test. --- common/src/main/java/org/apache/uniffle/common/util/ByteBufUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/apache/uniffle/common/util/ByteBufUtils.java b/common/src/main/java/org/apache/uniffle/common/util/ByteBufUtils.java index 84f77c34d..24f60e20e 100644 --- a/common/src/main/java/org/apache/uniffle/common/util/ByteBufUtils.java +++ b/common/src/main/java/org/apache/uniffle/common/util/ByteBufUtils.java @@ -80,10 +80,10 @@ public class ByteBufUtils { return from.retain().readSlice(length); } - public static final byte[] readBytes(ByteBuf buf) { + public static final byte[] readBytes(ByteBuf byteBuf) { + ByteBuf buf = byteBuf.duplicate(); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); - buf.resetReaderIndex(); return bytes; }