{"record":{"id":"99d22b29e0fdd5ae","repo":"JeffreySu/WeiXinMPSDK","slug":"0-timeout-infinite","errorCode":null,"errorMessage":"超时时间必须大于 0，或使用 Timeout.Infinite。 ","messagePattern":"超时时间必须大于 0，或使用 Timeout\\.Infinite。 ","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs","lineNumber":216,"sourceCode":"            return GetHttpResponseMessageAsync(url, data, CancellationToken.None, HttpCompletionOption.ResponseContentRead, timeOut, requestMethod, checkDataNotNull);\n        }\n\n        /// <summary>\n        /// 获取 HttpResponseMessage 对象，并支持调用方取消及流式响应。\n        /// </summary>\n        /// <returns>响应对象由调用方负责释放。</returns>\n        public async Task<HttpResponseMessage> GetHttpResponseMessageAsync(\n            string url,\n            object data,\n            CancellationToken cancellationToken,\n            HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,\n            int timeOut = Config.TIME_OUT,\n            ApiRequestMethod requestMethod = ApiRequestMethod.POST,\n            bool checkDataNotNull = true)\n        {\n            if (timeOut <= 0 && timeOut != Timeout.Infinite)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeOut), \"超时时间必须大于 0，或使用 Timeout.Infinite。 \");\n            }\n\n            using var request = new HttpRequestMessage(GetHttpMethod(requestMethod), url);\n\n            switch (requestMethod)\n            {\n                case ApiRequestMethod.GET:\n                case ApiRequestMethod.DELETE:\n                    WeixinTrace.Log(url);\n                    break;\n                case ApiRequestMethod.POST:\n                case ApiRequestMethod.PUT:\n                case ApiRequestMethod.PATCH:\n                    if (checkDataNotNull)\n                    {\n                        _ = data ?? throw new ArgumentNullException($\"{nameof(data)} 不能为 null！\");\n                    }\n","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs#L198-L234","documentation":"ArgumentOutOfRangeException thrown by TenPayApiRequest.GetHttpResponseMessageAsync when the timeOut parameter is <= 0 and not Timeout.Infinite. The library validates that a request timeout is a positive value or explicitly infinite.","triggerScenarios":"Calling any TenPay V3 API request method (Get/Post/etc.) that forwards timeOut with 0, a negative number, or an uninitialized/default-like value.","commonSituations":"Passing a config value that defaulted to 0 when Config.TIME_OUT was overridden with an invalid value; computing a timeout dynamically and getting a negative result.","solutions":["Pass a positive timeout in milliseconds, or Timeout.Infinite (-1) for no timeout","Fix Config.TIME_OUT configuration so it is > 0","Clamp/validate user-supplied timeouts before calling"],"exampleFix":"// before\nawait request.GetAsync(url, timeOut: 0);\n// after\nawait request.GetAsync(url, timeOut: Timeout.Infinite); // or e.g. 30000","handlingStrategy":"validation","validationCode":"if (timeOut <= 0 && timeOut != Timeout.Infinite)\n    throw new ArgumentOutOfRangeException(nameof(timeOut), timeOut, \"timeOut 必须为正数或 Timeout.Infinite\");","typeGuard":null,"tryCatchPattern":"try { await request.GetAsync(url, timeOut: timeOut); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"timeOut\") { timeOut = Config.TIME_OUT; /* retry with default */ }","preventionTips":["Centralize timeout in Config.TIME_OUT and validate it at startup","Never pass raw config integers as timeouts without a > 0 check","Use Timeout.Infinite deliberately for long operations, not 0"],"tags":["wechat-pay","timeout","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}