Skip to content

Commit 40ebcec

Browse files
author
r00894298
committed
fix OOM problem when receive big response of SSE interface from backend
service.
1 parent af1104d commit 40ebcec

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceEventStreamProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ private void processStringLine(String line) {
325325

326326
private byte[] readALineOfBytesFromBuffer(ByteBuf buffer) {
327327
matchingDelimiterIndex = 0;
328+
int newLineStartPos = buffer.readerIndex();
328329
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream(buffer.readableBytes())) {
329330
while (buffer.readableBytes() > 0 && matchingDelimiterIndex < lineDelimiterBytes.length) {
330331
final byte b = buffer.readByte();
@@ -336,7 +337,7 @@ private byte[] readALineOfBytesFromBuffer(ByteBuf buffer) {
336337
if (matchingDelimiterIndex < lineDelimiterBytes.length) {
337338
// The newline character was not matched, so this part of the buffer does not constitute a complete line of
338339
// content and needs to remain in the buffer, waiting for the next segment to arrive for processing.
339-
buffer.writeBytes(bos.toByteArray());
340+
buffer.readerIndex(newLineStartPos);
340341
return null;
341342
}
342343
matchingDelimiterIndex = 0;

0 commit comments

Comments
 (0)