Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Unassigned: Batching handlers should dispose responses in case of excetpions [1011]

$
0
0
When a batch request is received in Web API, this request is spawn into multiple requests. When these requests are being executed one by one, there is a possibility that one of the request's processing could throw an exception(OperationCanceledException), in which case we need to dispose the responses which were previously successfully created.

Discussed with Yao about this.

DefaultODataBatchHandler:
```
public override async Task<HttpResponseMessage> ProcessBatchAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}

cancellationToken.ThrowIfCancellationRequested();

ValidateRequest(request);

IList<ODataBatchRequestItem> subRequests = await ParseBatchRequestsAsync(request);

try
{
IList<ODataBatchResponseItem> responses = await ExecuteRequestMessagesAsync(subRequests, cancellationToken);
return await CreateResponseMessageAsync(responses, request);
}
finally
{
foreach (ODataBatchRequestItem subRequest in subRequests)
{
request.RegisterForDispose(subRequest.GetResourcesForDisposal());
request.RegisterForDispose(subRequest);
}
}
}

public virtual async Task<IList<ODataBatchResponseItem>> ExecuteRequestMessagesAsync(IEnumerable<ODataBatchRequestItem> requests, CancellationToken cancellationToken)
{
if (requests == null)
{
throw Error.ArgumentNull("requests");
}

cancellationToken.ThrowIfCancellationRequested();

IList<ODataBatchResponseItem> responses = new List<ODataBatchResponseItem>();
foreach (ODataBatchRequestItem request in requests)
{
responses.Add(await request.SendRequestAsync(Invoker, cancellationToken));
}

return responses;
}

```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>