From 798813bbc2979531e7bf11aed53516c21cee2d83 Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Wed, 21 Aug 2024 14:04:00 +0300 Subject: [PATCH] channel: reject oversized messages on the sender side. Reject oversized messages on the sender side, keeping the receiver side rejection intact. This should provide minimal low-level plumbing for clients to attempt application level corrective actions on the requestor side, if the high-level protocol is designed with this in mind. Signed-off-by: Krisztian Litkey --- channel.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/channel.go b/channel.go index feafd9a6b..1af2a8408 100644 --- a/channel.go +++ b/channel.go @@ -143,10 +143,10 @@ func (ch *channel) recv() (messageHeader, []byte, error) { } func (ch *channel) send(streamID uint32, t messageType, flags uint8, p []byte) error { - // TODO: Error on send rather than on recv - //if len(p) > messageLengthMax { - // return status.Errorf(codes.InvalidArgument, "refusing to send, message length %v exceed maximum message size of %v", len(p), messageLengthMax) - //} + if len(p) > messageLengthMax { + return status.Errorf(codes.ResourceExhausted, "refusing to send, message length %v exceed maximum message size of %v", len(p), messageLengthMax) + } + if err := writeMessageHeader(ch.bw, ch.hwbuf[:], messageHeader{Length: uint32(len(p)), StreamID: streamID, Type: t, Flags: flags}); err != nil { return err }