{"record":{"id":"55e3b9f7a09ac2c6","repo":"valyala/fasthttp","slug":"cannot-compress-data-due-to-high-load","errorCode":null,"errorMessage":"cannot compress data due to high load","messagePattern":"cannot compress data due to high load","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"stackless/writer.go","lineNumber":108,"sourceCode":"\nfunc (w *writer) do(op op) error {\n\tw.op = op\n\tif !stacklessWriterFunc(w) {\n\t\treturn errHighLoad\n\t}\n\terr := w.err\n\tif err != nil {\n\t\treturn err\n\t}\n\tif w.xw.bb != nil && len(w.xw.bb.B) > 0 {\n\t\t_, err = w.dstW.Write(w.xw.bb.B)\n\t}\n\tw.xw.Reset()\n\n\treturn err\n}\n\nvar errHighLoad = errors.New(\"cannot compress data due to high load\")\n\nvar (\n\tstacklessWriterFuncOnce sync.Once\n\tstacklessWriterFuncFunc func(ctx any) bool\n)\n\nfunc stacklessWriterFunc(ctx any) bool {\n\tstacklessWriterFuncOnce.Do(func() {\n\t\tstacklessWriterFuncFunc = NewFunc(writerFunc)\n\t})\n\treturn stacklessWriterFuncFunc(ctx)\n}\n\nfunc writerFunc(ctx any) {\n\tw := ctx.(*writer) //nolint:forcetypeassert\n\tswitch w.op {\n\tcase opWrite:\n\t\tw.n, w.err = w.zw.Write(w.p)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/stackless/writer.go#L90-L126","documentation":"errHighLoad (unexported, in stackless/writer.go) is returned by the stackless compressor's do function when the system is under high load and it cannot afford to compress data. The stackless package conserves stack/allocations and backs off compression rather than exhausting resources.","triggerScenarios":"Writing compressed output through the stackless writer while its load guard indicates high load; do() returns errHighLoad instead of compressing.","commonSituations":"Servers under heavy CPU/alloc pressure with compression enabled; small stacks / constrained environments where stackless compression backs off.","solutions":["Reduce overall load (throttle requests, add backpressure) so compression can proceed.","Disable or lower compression usage when under high load.","Retries: the error is transient; retry the write once load drops."],"exampleFix":"// before\nif err := sw.Flush(); err != nil { return err } // may be errHighLoad\n// after\nif err := sw.Flush(); err != nil {\n    if errors.Is(err, errHighLoad) { /* shed load or retry later */ }\n    return err\n}","handlingStrategy":"retry","validationCode":"// no pre-validation possible: errHighLoad is produced internally under load\n// mitigate by limiting concurrent compressing writers beforehand","typeGuard":null,"tryCatchPattern":"if err := sw.Flush(); err != nil {\n    if strings.Contains(err.Error(), \"high load\") {\n        time.Sleep(backoff)\n        // retry once load decreases\n    }\n    return err\n}","preventionTips":["Throttle concurrent compression work to keep system load low.","Treat this error as transient: retry with backoff.","Consider bypassing compression under high load.","Monitor CPU/alloc pressure to predict compression backoff."],"tags":["compression","high-load","stackless"],"backgroundTag":"compression-high-load","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}