Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions core/src/main/java/io/grpc/internal/MessageFramer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.grpc.Drainable;
import io.grpc.KnownLength;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -147,6 +148,8 @@ public void writePayload(InputStream message) {
.withDescription("Failed to frame message")
.withCause(e)
.asRuntimeException();
} catch (StatusRuntimeException e) {
throw e;
} catch (RuntimeException e) {
throw Status.INTERNAL
.withDescription("Failed to frame message")
Expand All @@ -170,13 +173,6 @@ private int writeUncompressed(InputStream message, int messageLength) throws IOE
}
BufferChainOutputStream bufferChain = new BufferChainOutputStream();
int written = writeToOutputStream(message, bufferChain);
if (maxOutboundMessageSize >= 0 && written > maxOutboundMessageSize) {
throw Status.RESOURCE_EXHAUSTED
.withDescription(
String.format(
Locale.US, "message too large %d > %d", written , maxOutboundMessageSize))
.asRuntimeException();
}
writeBufferChain(bufferChain, false);
return written;
}
Expand Down Expand Up @@ -238,6 +234,13 @@ private int writeKnownLengthUncompressed(InputStream message, int messageLength)
*/
private void writeBufferChain(BufferChainOutputStream bufferChain, boolean compressed) {
int messageLength = bufferChain.readableBytes();
if (maxOutboundMessageSize >= 0 && messageLength > maxOutboundMessageSize) {
throw Status.RESOURCE_EXHAUSTED
.withDescription(
String.format(
Locale.US, "message too large %d > %d", messageLength , maxOutboundMessageSize))
.asRuntimeException();
}
headerScratch.clear();
headerScratch.put(compressed ? COMPRESSED : UNCOMPRESSED).putInt(messageLength);
WritableBuffer writeableHeader = bufferAllocator.allocate(HEADER_LENGTH);
Expand Down