{"record":{"id":"0c2bda626e93e839","repo":"slimtoolkit/slim","slug":"setting-write-timeout-v","errorCode":null,"errorMessage":"setting write timeout: %v","messagePattern":"setting write timeout: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/probe/http/internal/fastcgi.go","lineNumber":100,"sourceCode":"\t\tenvJSON, _ := json.Marshal(env)\n\t\tlog.Debugf(\"HTTP probe - FastCGI env - %s\", string(envJSON))\n\t}\n\n\tctx := r.Context()\n\tdialer := net.Dialer{Timeout: t.DialTimeout}\n\tfcgiBackend, err := DialWithDialerContext(ctx, network, address, dialer)\n\tif err != nil {\n\t\t// TODO: wrap in a special error type if the dial failed, so retries can happen if enabled\n\t\treturn nil, fmt.Errorf(\"dialing backend: %v\", err)\n\t}\n\t// fcgiBackend gets closed when response body is closed (see clientCloser)\n\n\t// read/write timeouts\n\tif err := fcgiBackend.SetReadTimeout(t.ReadTimeout); err != nil {\n\t\treturn nil, fmt.Errorf(\"setting read timeout: %v\", err)\n\t}\n\tif err := fcgiBackend.SetWriteTimeout(t.WriteTimeout); err != nil {\n\t\treturn nil, fmt.Errorf(\"setting write timeout: %v\", err)\n\t}\n\n\tcontentLength := r.ContentLength\n\tif contentLength == 0 {\n\t\tcontentLength, _ = strconv.ParseInt(r.Header.Get(\"Content-Length\"), 10, 64)\n\t}\n\n\tvar resp *http.Response\n\tswitch r.Method {\n\tcase http.MethodHead:\n\t\tresp, err = fcgiBackend.Head(env)\n\tcase http.MethodGet:\n\t\tresp, err = fcgiBackend.Get(env, r.Body, contentLength)\n\tcase http.MethodOptions:\n\t\tresp, err = fcgiBackend.Options(env)\n\tdefault:\n\t\tresp, err = fcgiBackend.Post(env, r.Method, r.Header.Get(\"Content-Type\"), r.Body, contentLength)\n\t}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/probe/http/internal/fastcgi.go#L82-L118","documentation":"RoundTrip mirrors the read-timeout step with fcgiBackend.SetWriteTimeout using the transport's WriteTimeout. Failure is wrapped as \"setting write timeout: %v\". As with the read deadline, this almost always means the freshly dialed connection is no longer viable or cannot support deadlines.","triggerScenarios":"RoundTrip where SetReadTimeout succeeded but SetWriteTimeout failed — conn dropped between the two calls, or the connection implementation rejects deadline operations (unsupported deadline on some unix/mock conns).","commonSituations":"Flaky backend connections (worker killed between deadline calls); custom/unix socket transports lacking deadline support; zero or absurdly large WriteTimeout values interacting badly with the underlying conn.","solutions":["Read the wrapped cause; if deadlines are unsupported on this conn type, disable/raise WriteTimeout.","Verify the FastCGI backend stays alive across the request (no OOM kills, worker exhaustion).","Set an explicit positive WriteTimeout on the transport instead of relying on defaults.","Retry the request — the dial is retryable per code comments, and the failure may be transient."],"exampleFix":"// before\nif err := fcgiBackend.SetWriteTimeout(t.WriteTimeout); err != nil { ... } // WriteTimeout = 0\n// after\n// transport config\nt := FastCGITransport{ WriteTimeout: 30 * time.Second }","handlingStrategy":"retry","validationCode":"if t.WriteTimeout <= 0 {\n    return fmt.Errorf(\"configure a positive WriteTimeout on FastCGITransport\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := fcgiTransport.RoundTrip(req)\nif err != nil && strings.Contains(err.Error(), \"setting write timeout\") {\n    return retryRoundTrip(req) // transient conn drop between deadline calls\n}","preventionTips":["Configure an explicit positive WriteTimeout instead of defaults/zero.","Treat single failed RoundTrip as transient: retry once before surfacing.","Ensure the FastCGI backend remains healthy (no restarts mid-request)."],"tags":["fastcgi","timeout","http-probe"],"backgroundTag":"set-deadline-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}