Skip to content

Commit 82a81e2

Browse files
committed
fix(tools): wait for all ACKs before closing send side
Signed-off-by: Alfredo Gutierrez <alfredo@hashgraph.com>
1 parent bb6328f commit 82a81e2

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

tools-and-tests/tools/src/main/java/org/hiero/block/tools/capacity/NetworkCapacityClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ private BlockStreamPublishClient createPublishClient() {
100100

101101
private void streamBlocksFromFolder(BlockStreamPublishClient publishClient) throws IOException {
102102
List<Path> blockFiles = Files.list(recordingFolder)
103-
.filter(path -> path.toString().endsWith(".blk.gz") || path.toString().endsWith(".blk"))
103+
.filter(path ->
104+
path.toString().endsWith(".blk.gz") || path.toString().endsWith(".blk"))
104105
.sorted()
105106
.collect(Collectors.toList());
106107

@@ -152,6 +153,12 @@ private void streamBlocksFromFolder(BlockStreamPublishClient publishClient) thro
152153
metrics.reportPeriodic();
153154
}
154155

156+
// Wait for all ACKs to arrive before half-closing the send side.
157+
// The last ACK is in-flight from the server while we finish the send loop.
158+
long ackDeadline = System.currentTimeMillis() + 2_000;
159+
while (metrics.getTotalBlocksAcked() < metrics.getTotalBlocks() && System.currentTimeMillis() < ackDeadline) {
160+
LockSupport.parkNanos(10_000_000L);
161+
}
155162
requestPipeline.onComplete();
156163

157164
try {

tools-and-tests/tools/src/main/java/org/hiero/block/tools/capacity/NetworkCapacityServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ public void onNext(final PublishStreamRequestUnparsed req) {
139139
if (items.getLast().hasBlockProof() && hasReceivedBlockHeader) {
140140
metrics.incrementBlocks();
141141
System.out.printf(
142-
"[SERVER] Completed block %d (Total %d).%n",
143-
currentBlockNumber, metrics.getTotalBlocks());
142+
"[SERVER] Completed block %d (Total %d).%n", currentBlockNumber, metrics.getTotalBlocks());
144143

145144
PublishStreamResponse response = PublishStreamResponse.newBuilder()
146145
.acknowledgement(PublishStreamResponse.BlockAcknowledgement.newBuilder()

0 commit comments

Comments
 (0)