{"record":{"id":"591ce4561e6efafc","repo":"valyala/fasthttp","slug":"error-when-reading-s-headers-w-buffer-size-d","errorCode":null,"errorMessage":"error when reading %s headers: %w: buffer size=%d","messagePattern":"error when reading (.+?) headers: %w: buffer size=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":2301,"sourceCode":"\t}\n\n\t// Buggy servers may leave trailing CRLFs after http body.\n\t// Treat this case as EOF.\n\tif isOnlyCRLF(b) {\n\t\treturn io.EOF\n\t}\n\n\tif err != bufio.ErrBufferFull {\n\t\treturn headerErrorMsg(typ, err, b, secureErrorLogMessage)\n\t}\n\treturn &ErrSmallBuffer{\n\t\terror: headerErrorMsg(typ, ErrSmallReadBuffer, b, secureErrorLogMessage),\n\t}\n}\n\nfunc headerErrorMsg(typ string, err error, b []byte, secureErrorLogMessage bool) error {\n\tif secureErrorLogMessage {\n\t\treturn fmt.Errorf(\"error when reading %s headers: %w: buffer size=%d\", typ, err, len(b))\n\t}\n\treturn fmt.Errorf(\"error when reading %s headers: %w: buffer size=%d, contents: %s\", typ, err, len(b), bufferSnippet(b))\n}\n\n// Read reads request header from r.\n//\n// io.EOF is returned if r is closed before reading the first header byte.\nfunc (h *RequestHeader) Read(r *bufio.Reader) error {\n\treturn h.readLoop(r, true)\n}\n\n// readLoop reads request header from r optionally loops until it has enough data.\n//\n// io.EOF is returned if r is closed before reading the first header byte.\nfunc (h *RequestHeader) readLoop(r *bufio.Reader, waitForMore bool) error {\n\tn := 1\n\tfor {\n\t\terr := h.tryRead(r, n)","sourceCodeStart":2283,"sourceCodeEnd":2319,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L2283-L2319","documentation":"headerErrorMsg formats the final error for request/response header reads. In secure-error-log mode it hides the sniffed buffer contents and only reports the message plus buffer size, to avoid leaking request/response data into logs.","triggerScenarios":"Any header read error where RequestHeader/ResponseHeader.secureErrorLogMessage is true (set via SetSecureErrorLogger) — the wrapped error (e.g. ErrSmallReadBuffer) is reported with typ 'request'/'response' and the buffer length instead of its contents.","commonSituations":"Production servers with secure logging enabled hitting small-buffer header errors; developers confused why the error no longer shows header contents.","solutions":["Increase ReadBufferSize (server or client) if ErrSmallReadBuffer is the cause","Temporarily disable secure error logging in dev to see offending header contents","Reduce the size of the headers being sent","Keep secure logging on in production and rely on buffer size in the message to size buffers"],"exampleFix":"// before\ns := &fasthttp.Server{ReadBufferSize: 4096}\n// after\ns := &fasthttp.Server{ReadBufferSize: 65536}","handlingStrategy":"type-guard","validationCode":"// pick ReadBufferSize >= largest expected header block before deploying","typeGuard":"func isSmallReadBuffer(err error) bool { return errors.Is(err, fasthttp.ErrSmallReadBuffer) || errors.As(err, new(*fasthttp.ErrSmallBuffer)) }","tryCatchPattern":"if err := server.ServeConn(...); err != nil { if isSmallReadBuffer(err) { log.Printf(\"buffer too small: %v\", err) } } // in dev call srv.SetSecureErrorLogger(false) to see contents","preventionTips":["Enable secure logging only in production; disable locally when debugging header issues","Size buffers from the reported buffer-size value","Keep header sizes bounded and tested"],"tags":["network","fasthttp","headers","security"],"backgroundTag":"header-read-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}