简体   繁体   English

控制台应用程序中的最大并行任务,以及调用 API 时如何处理“将内容复制到流时出错”

[英]Max parallel tasks in Console App, and how to handle "Error while copying content to stream" when calling API

I'm working on an integration that handles several large datasets (around 3M records or so, growing daily) which are pulling from a vendor OData API in chunks.我正在处理一个集成,它可以处理从供应商 OData API 分块提取的几个大型数据集(大约 3M 条记录左右,每天都在增长)。 When I run it/debug locally, the integration will run to completion without errors.当我在本地运行它/调试时,集成将运行完成而没有错误。 However, as soon as I put it out on our PROD server, it will sometimes fail with "Error while copying content to stream" on a given chunk of data.但是,一旦我把它放到我们的 PROD 服务器上,它有时会在给定的数据块上失败并显示“将内容复制到流时出错”。 I'm having trouble figuring out the reason, and could use some help.我无法找出原因,并且可以使用一些帮助。

Each request is wrapped in a using statement and should be disposing of itself cleanly.每个请求都包含在 using 语句中,并且应该干净地处理自己。 Usually, it does.通常,确实如此。 Again, this all works perfectly on my local machine, but the server has a bit of trouble after it's into pulling millions of records.同样,这一切都在我的本地机器上完美运行,但是服务器在提取数百万条记录后遇到了一些麻烦。 I have added extra logging at virtually every step to catch the specific error, but it's still not clear how to handle (or avoid) this error.我几乎在每一步都添加了额外的日志记录以捕获特定错误,但仍不清楚如何处理(或避免)此错误。 It isn't consistent at all... totally intermittent and inconsistent.它根本不一致……完全断断续续且不一致。

The code where the error throws:引发错误的代码:

using (WebRequestHandler webRequestHandler = new WebRequestHandler())
{
    using (HttpClient httpClient = new HttpClient(webRequestHandler))
    {
        httpClient.Timeout = TimeSpan.FromMinutes(15);

        ConfigureJsonClient(httpClient, syncConfig.ApiEndpoint, syncConfig.ApiAuthKey);

        apiCommand = "http://foo/with/filtering";

        responseMessage = Task.Run(async () => await httpClient.GetAsync(apiCommand)
            .ConfigureAwait(true)).Result;
    }
}

The error:错误:

API Error Occurred - RETRYING... Foo: 2 | API CALL: https://foo... | EXCEPTION: One or more errors occurred. | INNER EXCEPTION: Error while copying content to a stream. | STACKTRACE:    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at FooNamespace.Processor.GetDataFromApi(SyncConfig syncConfig, String collection, List`1 nonDatedCollectionList, Int32 skipIndex, Int32 retryCount, Int32 taskId)

I am also trying to run as many parallel tasks as I can to pull these large datasets in pre-defined chunks (data pages) using skip/take.我还尝试运行尽可能多的并行任务,以使用跳过/获取将这些大型数据集提取到预定义的块(数据页)中。 No matter what I do, even locally, the max number of Tasks I can spin up in parallel is 40. Is there a reason for this limitation?无论我做什么,即使是在本地,我可以并行启动的最大任务数是 40。这个限制有什么原因吗?

Is it possible the parallel tasks are conflicting with each other somehow when hitting the API?访问 API 时,并行任务是否可能以某种方式相互冲突? These should appear as completely separate, isolated calls...这些应该显示为完全独立的、孤立的调用......

Any and all help is much appreciated.非常感谢任何和所有帮助。

I've got a similar exception Error while copying content to a stream . Error while copying content to a stream On the inner exception I've got System.IO.IOException: The decryption operation failed .在内部异常中,我有System.IO.IOException: The decryption operation failed I found that the server is sending the content compressed without the header content-encoding: gzip .我发现服务器正在发送没有 header content-encoding: gzip压缩的内容。 Change de default value of the AutomaticDecompression property on HttpClientHandler solve the problem.更改HttpClientHandlerAutomaticDecompression属性的默认值解决问题。

HttpClientHandler httpClientHandler = new HttpClientHandler();
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
using (var client = new HttpClient(httpClientHandler))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# - HTTP 在并行任务中运行随机失败,并出现:将内容复制到 stream 时出错 - C# - HTTP Get run in parallel tasks randomly fails with: Error while copying content to stream Web Api 请求抛出“将内容复制到流时出错”。 - Web Api Request Throws "Error while copying content to a stream." C# - 将内容复制到流时出错 - C# - Error while copying content to a stream SendGrid 抛出“将内容复制到流时出错” - SendGrid throws "Error while copying content to a stream" 将内容复制到流时出错。? - Error while copying content to a stream.? C# Web API 服务 - HttpRequestException:将内容复制到流时出错 - C# Web API Service - HttpRequestException: Error while copying content to a stream .NET 5 在抛出自定义异常时将内容复制到 stream 时产生错误 - .NET 5 produces Error while copying content to a stream when throwing custom exceptions 将内容复制到流中时,C#.Net Standard HttpClient错误 - C# .Net Standard HttpClient Error while copying content to a stream C# HttpClient 在将内容复制到流时随机出错 - C# HttpClient randomly getting error while copying content to a stream C# - 将内容复制到 stream 时出错 - (异步 HTTP 请求) - C# - Error while copying content to a stream - (Async HTTP Request)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM