{"record":{"id":"76d4377edd3add2f","repo":"caddyserver/caddy","slug":"timeout-cannot-be-less-than-0","errorCode":null,"errorMessage":"timeout cannot be less than 0","messagePattern":"timeout cannot be less than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/logging/netwriter.go","lineNumber":77,"sourceCode":"// Provision sets up the module.\nfunc (nw *NetWriter) Provision(ctx caddy.Context) error {\n\trepl := caddy.NewReplacer()\n\taddress, err := repl.ReplaceOrErr(nw.Address, true, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid host in address: %v\", err)\n\t}\n\n\tnw.addr, err = caddy.ParseNetworkAddress(address)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing network address '%s': %v\", address, err)\n\t}\n\n\tif nw.addr.PortRangeSize() != 1 {\n\t\treturn fmt.Errorf(\"multiple ports not supported\")\n\t}\n\n\tif nw.DialTimeout < 0 {\n\t\treturn fmt.Errorf(\"timeout cannot be less than 0\")\n\t}\n\n\treturn nil\n}\n\nfunc (nw NetWriter) String() string {\n\treturn nw.addr.String()\n}\n\n// WriterKey returns a unique key representing this nw.\nfunc (nw NetWriter) WriterKey() string {\n\treturn nw.addr.String()\n}\n\n// OpenWriter opens a new network connection.\nfunc (nw NetWriter) OpenWriter() (io.WriteCloser, error) {\n\treconn := &redialerConn{\n\t\tnw:      nw,","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/logging/netwriter.go#L59-L95","documentation":"NetWriter.Provision validates that the optional dial_timeout is non-negative. A negative duration in JSON (or Caddyfile) has no meaningful semantics for a dialer and is rejected at provisioning.","triggerScenarios":"Setting dial_timeout to a negative value in the net writer config, e.g. {\"dial_timeout\": \"-5s\"} or 'dial_timeout -5s' in Caddyfile syntax.","commonSituations":"Sign typos in duration strings; templates subtracting from a timeout and going below zero; confusing a '0 means default' convention with negative sentinels.","solutions":["Set dial_timeout to a positive duration like 10s, or remove it to use the default","Use 0 (or omit) rather than a negative value to express 'default'"],"exampleFix":"// before\n{\"output\": {\"output\": \"net\", \"address\": \"udp/h:514\", \"dial_timeout\": \"-5s\"}}\n\n// after\n{\"output\": {\"output\": \"net\", \"address\": \"udp/h:514\", \"dial_timeout\": \"10s\"}}","handlingStrategy":"validation","validationCode":"if d, err := time.ParseDuration(cfg.DialTimeout); err == nil && d < 0 {\n    return fmt.Errorf(\"dial_timeout must be >= 0\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use positive durations or omit dial_timeout for the default","Template guards: clamp computed timeouts to 0 minimum"],"tags":["caddy","logging","network","timeout"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}