diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ChunkedReplicatedContent.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ChunkedReplicatedContent.java index 46c993c7149e..f291a6a32221 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ChunkedReplicatedContent.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/messaging/marshalling/ChunkedReplicatedContent.java @@ -87,16 +87,14 @@ public ByteBuf readChunk( ChannelHandlerContext ctx ) throws IOException @Override public ByteBuf readChunk( ByteBufAllocator allocator ) throws IOException { - if ( isEndOfInput() ) + if ( endOfInput ) { return null; } - // assume this is the last chunk - boolean lastChunk = true; ByteBuf buffer = allocator.buffer( chunkSize ); try { - buffer.writeBoolean( lastChunk ); + buffer.writerIndex( 1 ); // space for endOfInput marker if ( progress() == 0 ) { // extra metadata on first chunk @@ -105,14 +103,11 @@ public ByteBuf readChunk( ByteBufAllocator allocator ) throws IOException } if ( !byteBufAwareMarshal.encode( buffer ) ) { - this.endOfInput = true; - } - if ( isEndOfInput() != lastChunk ) - { - // status changed after writing to buffer. - buffer.setBoolean( 0, isEndOfInput() ); + endOfInput = true; } progress += buffer.readableBytes(); + assert progress > 0; // logic relies on this + buffer.setBoolean( 0, endOfInput ); return buffer; } catch ( Throwable e )