-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Possible inconvenient implementation of timeout in OData.Client #3131
Comments
@dotnetero Thanks for reporting this. As we investigate this further, please setup as following on the client side and try out:
public class CustomHttpClientFactory : IHttpClientFactory
{
private readonly HttpClient _httpClient;
public CustomHttpClientFactory(HttpClient httpClient)
{
_httpClient = httpClient;
}
public HttpClient CreateClient(string name)
{
return _httpClient;
}
}
var httpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(160)
};
var httpClientFactory= new CustomHttpClientFactory(httpClient);
var context = new Container(new Uri("https://localhost:7214/odata"))
{
HttpClientFactory = httpClientFactory
}; In your example, this will look like:IEvaluaDbUnitOfWork IUnitOfWorkFactory<IEvaluaDbUnitOfWork>.CreateUnitOfWork(string url, MergeOption mergeOption, int? timeout)
{
return new EvaluaDbUnitOfWork(() => new Evalua.Default.Container(new Uri(url)) { MergeOption = mergeOption, Timeout = timeOut ?? 30, ReadWriteTimeout = timeOut ?? 30, HttpClientFactory = httpClientFactory});
} Let us know if this sort you out in the meantime. |
@dotnetero We will be removing the Timeout property and only allow this to be configured using |
@dotnetero You can also use the following in ServiceCollection(): var services = new ServiceCollection();
services.AddHttpClient("", client => // Note that the httpClient is not named
{
client.Timeout = TimeSpan.FromSeconds(160);
});
var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
IEvaluaDbUnitOfWork IUnitOfWorkFactory<IEvaluaDbUnitOfWork>.CreateUnitOfWork(string url, MergeOption mergeOption, int? timeout)
{
return new EvaluaDbUnitOfWork(() => new Evalua.Default.Container(new Uri(url)) { MergeOption = mergeOption, Timeout = timeOut ?? 30, ReadWriteTimeout = timeOut ?? 30, HttpClientFactory = httpClientFactory});
} |
@WanjohiSammy I am grateful for the time and the examples you share, for the moment my projects are already stable. |
I'm working in a data collector, on a distributed system, and some methods take me between 2 to 5 minutes.
The databases have a size greater than 500 gb, and it is required to obtain 19 complex queries, doing the service test, it responds correctly, so on the server side everything works correctly.
Perform tests with console clients, winforms, wpf and blazor server, in all of them it happens that when assigning the timeout in 5 minutes, in all cases the thread is canceled at minute 1 with 40 seconds.
Digging into the code of the OData.Client library, in the constructor of the HttpClientRequestMessage class, the HttpClient is initialized, and it has a default timeout of 1 minute and 40 seconds.
The timeout set by the developer is respected in the DataServiceContext timeout property. But the HttpClient is never notified of this change, so its default value is always maintained.
Add a line of code, to set the timeout of the DataServiceContext to the HttpClient, prior to requesting data from the server, working properly according to the needs of each scenario.
The problem I see, is that I don't have full knowledge of the entire library, and if it is necessary to make this change in the proper way, so as not to break something else.
Assemblies affected
Microsoft.OData.Client
Reproduce steps
When you run they should see the following result:
Expected result
To be able to modify the default value of the timeout in the DataServiceContext constructor, and that it is respected in each request made to the multiple services.
Actual result
Any request that exceeds the wait for the response in 1 minute and 40 seconds, is automatically canceled, as shown in the image above.
Additional detail
The HttpClient is never notified that the default timeout value has been changed.
The text was updated successfully, but these errors were encountered: