Prechádzať zdrojové kódy

Merge pull request #217 from Shopify/configurable-max-response

Make maximum-parsable response size configurable
Evan Huus 11 rokov pred
rodič
commit
b099e0411d
2 zmenil súbory, kde vykonal 7 pridanie a 3 odobranie
  1. 1 3
      response_header.go
  2. 6 0
      sarama.go

+ 1 - 3
response_header.go

@@ -7,14 +7,12 @@ type responseHeader struct {
 	correlationID int32
 	correlationID int32
 }
 }
 
 
-const maxMessageSize = 32 * 1024 * 1024 // 32MB
-
 func (r *responseHeader) decode(pd packetDecoder) (err error) {
 func (r *responseHeader) decode(pd packetDecoder) (err error) {
 	r.length, err = pd.getInt32()
 	r.length, err = pd.getInt32()
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	if r.length <= 4 || r.length > maxMessageSize {
+	if r.length <= 4 || r.length > MaxResponseSize {
 		return DecodingError{Info: fmt.Sprintf("Message too large or too small. Got %d", r.length)}
 		return DecodingError{Info: fmt.Sprintf("Message too large or too small. Got %d", r.length)}
 	}
 	}
 
 

+ 6 - 0
sarama.go

@@ -32,3 +32,9 @@ var PanicHandler func(interface{})
 // with Kafka's default `socket.request.max.bytes`, which is the largest request the broker will attempt
 // with Kafka's default `socket.request.max.bytes`, which is the largest request the broker will attempt
 // to process.
 // to process.
 var MaxRequestSize uint32 = 100 * 1024 * 1024
 var MaxRequestSize uint32 = 100 * 1024 * 1024
+
+// MaxResponseSize is the maximum size (in bytes) of any response that Sarama will attempt to parse. If
+// a broker returns a response message larger than this value, Sarama will return a DecodingError. The
+// default of 100 MiB is aligned with Kafka's default `socket.request.max.bytes`, which is the largest
+// request the broker will attempt to process.
+var MaxResponseSize int32 = 100 * 1024 * 1024