diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/exchange/ExchangeServiceTests.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/exchange/ExchangeServiceTests.java index d063883876dfc..78042a8587350 100644 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/exchange/ExchangeServiceTests.java +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/exchange/ExchangeServiceTests.java @@ -398,18 +398,25 @@ public void messageReceived( ) throws Exception { FilterTransportChannel filterChannel = new FilterTransportChannel(channel) { @Override - public void sendResponse(TransportResponse response) throws IOException { - ExchangeResponse exchangeResponse = (ExchangeResponse) response; - Page page = exchangeResponse.takePage(); + public void sendResponse(TransportResponse transportResponse) throws IOException { + ExchangeResponse origResp = (ExchangeResponse) transportResponse; + Page page = origResp.takePage(); if (page != null) { IntBlock block = page.getBlock(0); for (int i = 0; i < block.getPositionCount(); i++) { if (block.getInt(i) == disconnectOnSeqNo) { + page.releaseBlocks(); throw new IOException("page is too large"); } } } - super.sendResponse(response); + ExchangeResponse newResp = new ExchangeResponse(page, origResp.finished()); + origResp.decRef(); + while (origResp.hasReferences()) { + newResp.incRef(); + origResp.decRef(); + } + super.sendResponse(newResp); } }; handler.messageReceived(request, filterChannel, task);