Skip to content

Commit

Permalink
Avoid possible deadlock in synchronous Send using WaitAndUnwrapExcept…
Browse files Browse the repository at this point in the history
…ion from Nito.AsyncEx
  • Loading branch information
OndraFiedler committed Nov 17, 2020
1 parent 68cfa53 commit edcdc4c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 106 deletions.
3 changes: 2 additions & 1 deletion Src/Recombee.ApiClient/Recombee.ApiClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.0" />
</ItemGroup>

<PropertyGroup>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
151 changes: 76 additions & 75 deletions Src/Recombee.ApiClient/RecombeeClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Nito.AsyncEx.Synchronous;
using Recombee.ApiClient.ApiRequests;
using Recombee.ApiClient.Bindings;

Expand Down Expand Up @@ -34,9 +35,9 @@ public async Task<PropertyInfo> SendAsync(GetItemPropertyInfo request)
/// <returns>Response from the API</returns>
public PropertyInfo Send(GetItemPropertyInfo request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -63,9 +64,9 @@ public async Task<IEnumerable<PropertyInfo>> SendAsync(ListItemProperties reques
/// <returns>Response from the API</returns>
public IEnumerable<PropertyInfo> Send(ListItemProperties request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand Down Expand Up @@ -93,9 +94,9 @@ public async Task<IEnumerable<Series>> SendAsync(ListSeries request)
/// <returns>Response from the API</returns>
public IEnumerable<Series> Send(ListSeries request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -122,9 +123,9 @@ public async Task<IEnumerable<SeriesItem>> SendAsync(ListSeriesItems request)
/// <returns>Response from the API</returns>
public IEnumerable<SeriesItem> Send(ListSeriesItems request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand Down Expand Up @@ -152,9 +153,9 @@ public async Task<IEnumerable<Group>> SendAsync(ListGroups request)
/// <returns>Response from the API</returns>
public IEnumerable<Group> Send(ListGroups request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -181,9 +182,9 @@ public async Task<IEnumerable<GroupItem>> SendAsync(ListGroupItems request)
/// <returns>Response from the API</returns>
public IEnumerable<GroupItem> Send(ListGroupItems request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -210,9 +211,9 @@ public async Task<PropertyInfo> SendAsync(GetUserPropertyInfo request)
/// <returns>Response from the API</returns>
public PropertyInfo Send(GetUserPropertyInfo request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -239,9 +240,9 @@ public async Task<IEnumerable<PropertyInfo>> SendAsync(ListUserProperties reques
/// <returns>Response from the API</returns>
public IEnumerable<PropertyInfo> Send(ListUserProperties request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -268,9 +269,9 @@ public async Task<IEnumerable<DetailView>> SendAsync(ListItemDetailViews request
/// <returns>Response from the API</returns>
public IEnumerable<DetailView> Send(ListItemDetailViews request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -297,9 +298,9 @@ public async Task<IEnumerable<DetailView>> SendAsync(ListUserDetailViews request
/// <returns>Response from the API</returns>
public IEnumerable<DetailView> Send(ListUserDetailViews request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -326,9 +327,9 @@ public async Task<IEnumerable<Purchase>> SendAsync(ListItemPurchases request)
/// <returns>Response from the API</returns>
public IEnumerable<Purchase> Send(ListItemPurchases request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -355,9 +356,9 @@ public async Task<IEnumerable<Purchase>> SendAsync(ListUserPurchases request)
/// <returns>Response from the API</returns>
public IEnumerable<Purchase> Send(ListUserPurchases request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -384,9 +385,9 @@ public async Task<IEnumerable<Rating>> SendAsync(ListItemRatings request)
/// <returns>Response from the API</returns>
public IEnumerable<Rating> Send(ListItemRatings request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -413,9 +414,9 @@ public async Task<IEnumerable<Rating>> SendAsync(ListUserRatings request)
/// <returns>Response from the API</returns>
public IEnumerable<Rating> Send(ListUserRatings request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -442,9 +443,9 @@ public async Task<IEnumerable<CartAddition>> SendAsync(ListItemCartAdditions req
/// <returns>Response from the API</returns>
public IEnumerable<CartAddition> Send(ListItemCartAdditions request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -471,9 +472,9 @@ public async Task<IEnumerable<CartAddition>> SendAsync(ListUserCartAdditions req
/// <returns>Response from the API</returns>
public IEnumerable<CartAddition> Send(ListUserCartAdditions request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -500,9 +501,9 @@ public async Task<IEnumerable<Bookmark>> SendAsync(ListItemBookmarks request)
/// <returns>Response from the API</returns>
public IEnumerable<Bookmark> Send(ListItemBookmarks request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -529,9 +530,9 @@ public async Task<IEnumerable<Bookmark>> SendAsync(ListUserBookmarks request)
/// <returns>Response from the API</returns>
public IEnumerable<Bookmark> Send(ListUserBookmarks request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -558,9 +559,9 @@ public async Task<IEnumerable<ViewPortion>> SendAsync(ListItemViewPortions reque
/// <returns>Response from the API</returns>
public IEnumerable<ViewPortion> Send(ListItemViewPortions request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -587,9 +588,9 @@ public async Task<IEnumerable<ViewPortion>> SendAsync(ListUserViewPortions reque
/// <returns>Response from the API</returns>
public IEnumerable<ViewPortion> Send(ListUserViewPortions request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -616,9 +617,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendItemsToUser request
/// <returns>Response from the API</returns>
public RecommendationResponse Send(RecommendItemsToUser request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -645,9 +646,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendUsersToUser request
/// <returns>Response from the API</returns>
public RecommendationResponse Send(RecommendUsersToUser request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -674,9 +675,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendItemsToItem request
/// <returns>Response from the API</returns>
public RecommendationResponse Send(RecommendItemsToItem request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -703,9 +704,9 @@ public async Task<RecommendationResponse> SendAsync(RecommendUsersToItem request
/// <returns>Response from the API</returns>
public RecommendationResponse Send(RecommendUsersToItem request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}


Expand All @@ -732,9 +733,9 @@ public async Task<SearchResponse> SendAsync(SearchItems request)
/// <returns>Response from the API</returns>
public SearchResponse Send(SearchItems request)
{
var task = SendAsync(request);
RaiseExceptionOnFault(task);
return task.Result;
var task = Task.Run(async () => await SendAsync(request));
var result = task.WaitAndUnwrapException();
return result;
}

private object ParseOneBatchResponse(string json, int statusCode, Request request)
Expand Down
Loading

0 comments on commit edcdc4c

Please sign in to comment.