|
21 | 21 | import org.elasticsearch.core.internal.io.IOUtils;
|
22 | 22 | import org.elasticsearch.Version;
|
23 | 23 | import org.elasticsearch.action.ActionListener;
|
| 24 | +import org.elasticsearch.Version; |
| 25 | +import org.elasticsearch.action.ActionListener; |
| 26 | +import org.elasticsearch.cli.SuppressForbidden; |
24 | 27 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
25 | 28 | import org.elasticsearch.common.bytes.BytesReference;
|
26 | 29 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
27 | 30 | import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
28 | 31 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
| 32 | +import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; |
29 | 33 | import org.elasticsearch.common.io.stream.StreamInput;
|
30 | 34 | import org.elasticsearch.common.network.NetworkService;
|
31 | 35 | import org.elasticsearch.common.settings.Settings;
|
|
35 | 39 | import org.elasticsearch.common.util.CancellableThreads;
|
36 | 40 | import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
37 | 41 | import org.elasticsearch.common.util.concurrent.EsExecutors;
|
| 42 | +import org.elasticsearch.core.internal.io.IOUtils; |
38 | 43 | import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
39 | 44 | import org.elasticsearch.mocksocket.MockServerSocket;
|
40 | 45 | import org.elasticsearch.mocksocket.MockSocket;
|
@@ -153,19 +158,20 @@ private void readMessage(MockChannel mockChannel, StreamInput input) throws IOEx
|
153 | 158 | if (msgSize == -1) {
|
154 | 159 | socket.getOutputStream().flush();
|
155 | 160 | } else {
|
156 |
| - BytesStreamOutput output = new BytesStreamOutput(); |
157 |
| - final byte[] buffer = new byte[msgSize]; |
158 |
| - input.readFully(buffer); |
159 |
| - output.write(minimalHeader); |
160 |
| - output.writeInt(msgSize); |
161 |
| - output.write(buffer); |
162 |
| - final BytesReference bytes = output.bytes(); |
163 |
| - if (TcpTransport.validateMessageHeader(bytes)) { |
164 |
| - InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); |
165 |
| - messageReceived(bytes.slice(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE, msgSize), |
166 |
| - mockChannel, mockChannel.profile, remoteAddress, msgSize); |
167 |
| - } else { |
168 |
| - // ping message - we just drop all stuff |
| 161 | + try (BytesStreamOutput output = new ReleasableBytesStreamOutput(msgSize, bigArrays)) { |
| 162 | + final byte[] buffer = new byte[msgSize]; |
| 163 | + input.readFully(buffer); |
| 164 | + output.write(minimalHeader); |
| 165 | + output.writeInt(msgSize); |
| 166 | + output.write(buffer); |
| 167 | + final BytesReference bytes = output.bytes(); |
| 168 | + if (TcpTransport.validateMessageHeader(bytes)) { |
| 169 | + InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); |
| 170 | + messageReceived(bytes.slice(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE, msgSize), |
| 171 | + mockChannel, mockChannel.profile, remoteAddress, msgSize); |
| 172 | + } else { |
| 173 | + // ping message - we just drop all stuff |
| 174 | + } |
169 | 175 | }
|
170 | 176 | }
|
171 | 177 | }
|
|
0 commit comments