diff --git a/docs/configuration.md b/docs/configuration.md index c6d869e..9adbb72 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -177,7 +177,7 @@ The value is a whole number of bytes, with or without a unit: `B`, `KB`, `MB`, ` **Examples:** `1048576`, `10MiB`, `2MB`, `512KiB` -A server can declare a `Content-Length` far larger than it sends, and the body is allocated from that declared length, so without a limit a single response can exhaust memory. A response above the limit fails with `body size exceeds the given limit` and is counted like any other error. +A server can declare a `Content-Length` far larger than it sends, and the body is allocated from that declared length, so without a limit a single response can exhaust memory. A response above the limit fails with `response body exceeds the body limit` and is counted like any other error. The limit applies per response in flight, and a declared Content-Length is allocated up to it, so the worst case is a few times the limit times the concurrency. It covers the requests scripts make as well. diff --git a/internal/sarin/scripthttp.go b/internal/sarin/scripthttp.go index f5f48c1..633ddf8 100644 --- a/internal/sarin/scripthttp.go +++ b/internal/sarin/scripthttp.go @@ -159,7 +159,7 @@ func (c *scriptHTTPClient) Do(r *script.HTTPRequest) (*script.HTTPResponse, erro } if err != nil { if errors.Is(err, fasthttp.ErrBodyTooLarge) { - err = types.ErrScriptHTTPBodyTooLarge + err = types.ErrResponseBodyTooLarge } return nil, types.NewScriptHTTPRequestError(r.Method, r.URL, err) } diff --git a/internal/sarin/worker.go b/internal/sarin/worker.go index 2d0897e..034ccc1 100644 --- a/internal/sarin/worker.go +++ b/internal/sarin/worker.go @@ -35,6 +35,10 @@ func statusCodeToString(code int) string { // responseErrorKey drops the local address, whose port would mint a stats entry per connection. func responseErrorKey(err error) string { + if errors.Is(err, fasthttp.ErrBodyTooLarge) { + return types.ErrResponseBodyTooLarge.Error() + } + message := err.Error() var opErr *net.OpError diff --git a/internal/types/errors.go b/internal/types/errors.go index 5f2610c..a6c4e4f 100644 --- a/internal/types/errors.go +++ b/internal/types/errors.go @@ -17,6 +17,8 @@ var ( ) ErrRemoteFileTooLarge = errors.New("remote file exceeds " + FormatByteSize(RemoteFetchLimit)) + + ErrResponseBodyTooLarge = errors.New("response body exceeds the body limit") ) type FieldParseError struct { @@ -415,7 +417,6 @@ var ( ErrScriptHTTPMethodEmpty = errors.New("http method cannot be empty") ErrScriptHTTPURLInvalid = errors.New("URL must be an absolute http or https URL") ErrScriptHTTPUnknownOption = errors.New("unknown option") - ErrScriptHTTPBodyTooLarge = errors.New("response body exceeds the body limit") ErrScriptJSONCycle = errors.New("cannot encode a table that contains itself") )