pnowojski commented on a change in pull request #12353:
URL: https://github.com/apache/flink/pull/12353#discussion_r434353668



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/BufferBuilder.java
##########
@@ -53,9 +55,13 @@ public BufferBuilder(MemorySegment memorySegment, 
BufferRecycler recycler) {
         * @return created matching instance of {@link BufferConsumer} to this 
{@link BufferBuilder}.
         */
        public BufferConsumer createBufferConsumer() {
+               if (buffer == null) {
+                       buffer = new NetworkBuffer(memorySegment, recycler);
+               } else {
+                       buffer.retainBuffer();
+               }

Review comment:
       I think this still leaves a window for the same error to happen. When 
`buffer == null`, the returned `BufferConsumer` could be recycled before the 
next call to `BufferBuilder#createBufferConsumer`.
   
   Even besides that, the other proposal:
   ```
        public BufferConsumer copyAndSync(BufferBuilder builder) {
                return new BufferConsumer(buffer.retainBuffer(), 
builder.positionMarker,
                        builder.positionMarker.cachedPosition);
        }
   ```
   I think it's cleaner as it avoids adding more mutable state in the 
`BufferBuilder`.




----------------------------------------------------------------
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.

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


Reply via email to