{"record":{"id":"814c9439287ba614","repo":"valyala/fasthttp","slug":"error-when-reading-response-trailer-w","errorCode":null,"errorMessage":"error when reading response trailer: %w","messagePattern":"error when reading response trailer: %w","errorType":"exception","errorClass":"ErrSmallBuffer","httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":2258,"sourceCode":"\tif len(b) == 0 {\n\t\t// Return ErrTimeout on any timeout.\n\t\tif x, ok := err.(interface{ Timeout() bool }); ok && x.Timeout() {\n\t\t\treturn ErrTimeout\n\t\t}\n\n\t\tif n == 1 || err == io.EOF {\n\t\t\treturn io.EOF\n\t\t}\n\n\t\t// This is for go 1.6 bug. See https://github.com/golang/go/issues/14121 .\n\t\tif err == bufio.ErrBufferFull {\n\t\t\tif h.secureErrorLogMessage {\n\t\t\t\treturn &ErrSmallBuffer{\n\t\t\t\t\terror: ErrReadingResponseTrailer,\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn &ErrSmallBuffer{\n\t\t\t\terror: fmt.Errorf(\"error when reading response trailer: %w\", ErrSmallReadBuffer),\n\t\t\t}\n\t\t}\n\n\t\treturn fmt.Errorf(\"error when reading response trailer: %w\", err)\n\t}\n\tb = mustPeekBuffered(r)\n\thh, headersLen, errParse := parseTrailer(b, h.h, h.disableNormalizing)\n\th.h = hh\n\tif errParse != nil {\n\t\tif err == io.EOF {\n\t\t\treturn err\n\t\t}\n\t\treturn headerError(\"response\", err, errParse, b, h.secureErrorLogMessage)\n\t}\n\tmustDiscard(r, headersLen)\n\treturn nil\n}\n","sourceCodeStart":2240,"sourceCodeEnd":2276,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L2240-L2276","documentation":"ReadTrailer failed while reading the trailer part of a chunked response after the body. When the failure is a small-buffer condition, fasthttp wraps ErrSmallReadBuffer into an ErrSmallBuffer with this trailer-specific message.","triggerScenarios":"Client reading a chunked HTTP response with trailers whose trailer section exceeds the remaining buffer space (ReadBufferSize too small for the trailers).","commonSituations":"Servers sending large trailers (e.g. Integrity-Digest, checksums) to a client with a small ReadBufferSize.","solutions":["Increase Client.ReadBufferSize","Reduce trailer size sent by the server","Disable trailers on the server side if not needed"],"exampleFix":"// before\nclient := &fasthttp.Client{ReadBufferSize: 2048}\n// after\nclient := &fasthttp.Client{ReadBufferSize: 16384}","handlingStrategy":"type-guard","validationCode":"// ensure server trailers fit: trailerBytes <= client.ReadBufferSize","typeGuard":"func isErrSmallBuffer(err error) bool { var e *fasthttp.ErrSmallBuffer; return errors.As(err, &e) }","tryCatchPattern":"if err := client.Do(req, resp); err != nil { if isErrSmallBuffer(err) && strings.Contains(err.Error(), \"trailer\") { /* enlarge ReadBufferSize */ } }","preventionTips":["Prefer larger ReadBufferSize when consuming chunked+trailer responses","Ask upstream to send small trailers or none"],"tags":["network","fasthttp","trailer","buffer-size"],"backgroundTag":"header-read-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}