{"record":{"id":"28b53052b4501af7","repo":"alibaba/open-code-review","slug":"timeout-sec-d-overflows-time-duration-max-d","errorCode":null,"errorMessage":"timeout_sec %d overflows time.Duration (max %d)","messagePattern":"timeout_sec (.+?) overflows time\\.Duration \\(max (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/llm/resolver.go","lineNumber":231,"sourceCode":"\tif err != nil {\n\t\treturn 0, false, fmt.Errorf(\"OCR_LLM_TIMEOUT: %w\", err)\n\t}\n\treturn d, true, nil\n}\n\n// validateTimeoutSec converts a config-file timeout (in seconds) to time.Duration.\n// Returns 0 for zero input (use default). Rejects negative values and overflow.\nfunc validateTimeoutSec(sec int) (time.Duration, error) {\n\tif sec == 0 {\n\t\treturn 0, nil\n\t}\n\tif sec < 0 {\n\t\treturn 0, fmt.Errorf(\"timeout_sec must be non-negative, got %d\", sec)\n\t}\n\t// Guard against overflow: time.Duration is int64 nanoseconds.\n\tmaxSec := int64(math.MaxInt64 / int64(time.Second))\n\tif int64(sec) > maxSec {\n\t\treturn 0, fmt.Errorf(\"timeout_sec %d overflows time.Duration (max %d)\", sec, maxSec)\n\t}\n\treturn time.Duration(sec) * time.Second, nil\n}\n\n// errBedrockNotConfigurable explains why the two url+token strategies reject the\n// bedrock protocol. Both describe a single HTTP endpoint and carry no place for\n// a region or a profile, and bedrock uses neither the url nor the token they do\n// carry. Accepting the value would switch transports and silently ignore the\n// rest of the block, so it is refused at the point it is read.\nfunc errBedrockNotConfigurable(key string) error {\n\treturn fmt.Errorf(\"%s cannot be %q: bedrock derives its host from aws_region and signs with the AWS credential chain, so it has no use for a url or a token; configure it as a provider instead (\\\"provider\\\": \\\"bedrock\\\")\",\n\t\tkey, ProtocolAnthropicBedrock)\n}\n\n// tryOCREnv reads OCR-specific environment variables.\nfunc tryOCREnv(modelOverride string) (ResolvedEndpoint, bool, error) {\n\turl := os.Getenv(envOCRLLMURL)\n\ttoken := os.Getenv(envOCRLLMToken)","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/llm/resolver.go#L213-L249","documentation":"time.Duration is int64 nanoseconds, so a timeout_sec beyond math.MaxInt64/1e9 seconds (~292 years) would overflow. validateTimeoutSec rejects such values with this message stating the value and the maximum allowed seconds. Practically only reachable with absurdly large integers in config or env.","triggerScenarios":"timeout_sec in a config.json provider/llm section, or OCR_LLM_TIMEOUT, set to an integer exceeding ~9223372036 seconds (e.g. 1e15).","commonSituations":"A generated or templated config inserting a sentinel like 9999999999999999 intending \"effectively infinite\" timeout.","solutions":["Lower timeout_sec to a sane value (e.g. 600 for 10 minutes)","Use 0 to select the library default (5 min) instead of an enormous sentinel","If you need \"no timeout\", use the largest practical value within range rather than an overflow-level sentinel"],"exampleFix":"// before\n\"timeout_sec\": 9999999999999999\n// after\n\"timeout_sec\": 0","handlingStrategy":"validation","validationCode":"const maxSec = math.MaxInt64 / int64(time.Second)\nif int64(sec) > maxSec {\n    return fmt.Errorf(\"timeout_sec %d exceeds max %d\", sec, maxSec)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"overflows time.Duration\") {\n    return fmt.Errorf(\"reduce timeout_sec: %w\", err)\n}","preventionTips":["Cap sentinel \"infinite\" timeouts at a safe value like 86400 (one day)","Clamp any computed timeout against math.MaxInt64/int64(time.Second)","Prefer 0 (default) over extreme sentinels in generated configs"],"tags":["config","validation","timeout","overflow"],"backgroundTag":"config-value-out-of-range","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}