stripe / stripe-dotnet

Stripe.net is a sync/async .NET 4.6.1+ client, and a portable class library for stripe.com.
Apache License 2.0
1.36k stars 571 forks source link

v46 hangs in ASP.NET #2998

Open agclark27 opened 2 days ago

agclark27 commented 2 days ago

Describe the bug

Beginning with 46.0.0, the changes to the backend Request/RequestAsync service methods result in all API calls hanging indefinitely when run on ASP.NET under .NET Framework v4.8. This appears to be related to a synchronization context deadlock of some kind, even though we're seeing this expected .ConfigureAwait(false) still in the source.

To Reproduce

In an ASP.NET project, attempt to call any Stripe API, such as this location service, even with an invalid object ID or API key:

var locationService = new Stripe.Terminal.LocationService();`
var location = locationService.Get("XX", null, new Stripe.RequestOptions { ApiKey = "sk_XX" });
Response.Write("END");
Response.End();

In this example, the call will hang on .Get and will hang indefinitely. If we debug the process, the hang is occurring here:

mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) Line 414
    at System.Threading\ManualResetEventSlim.cs(414)
mscorlib.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) Line 2982
    at System.Threading.Tasks\Task.cs(2982)
mscorlib.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) Line 2953
    at System.Threading.Tasks\Task.cs(2953)
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) Line 83
    at System.Runtime.CompilerServices\TaskAwaiter.cs(83)
[Waiting on Async Operation, double-click or press enter to view Async Call Stacks]
Stripe.net.dll!Stripe.Service.Request<Stripe.Terminal.Location>(Stripe.BaseAddress baseAddress, System.Net.Http.HttpMethod method, string path, Stripe.BaseOptions options, Stripe.RequestOptions requestOptions) Line 76
    at /_/src/Stripe.net/Services/_base/Service.cs(76)
Stripe.net.dll!Stripe.Terminal.LocationService.Get(string id, Stripe.Terminal.LocationGetOptions options, Stripe.RequestOptions requestOptions) Line 73
    at /_/src/Stripe.net/Services/Terminal/Locations/LocationService.cs(73)

This is the method where we're seeing it hang.

Expected behavior

The expected behavior is that the call returns immediately and does not hang.

OS

Windows

.NET version

.NET Framework 4.8

Library version

stripe-dotnet 46.1.0

API version

2024-09-30.acacia

corneliu-gavrilovici commented 1 day ago

I can confirm this one happens in my ASP.NET project also.

ramya-stripe commented 1 day ago

Thanks for reporting @agclark27 and for confirming @corneliu-gavrilovici We will look into this right away