-
Notifications
You must be signed in to change notification settings - Fork 164
Description
Example:
I work for a large company that utilizes DocuSign in a production environment. When calling the TemplatesApi.GetAsync method, a rare timeout error can occur after the default 30 minutes have expired if something went wrong during this process. I believe this isn't being handled properly all the way to the root call in SystemNetHttpClient.cs:
public DocuSignResponse SendRequest(DocuSignRequest request)
{
CancellationTokenSource cts = new CancellationTokenSource();
Task<DocuSignResponse> t = Task.Run(async () => await SendRequestAsync(request, cts.Token));
t.Wait();
return t.Result;
}
Running the Task.Run is a dangerous/bad practice when this can simply be awaited normally. By not passing a CancellationToken down the method chain, we have no opportunity for our API to manually cancel anything running. Also this may lead to spawning threads/exhaustion in a high I/O environment like our API integration.
A better and safer implementation may be:
public DocuSignResponse SendRequest(DocuSignRequest request, CancellationToken token)
{
return SendRequestAsync(request, token).GetAwaiter().GetResult();
}
at that point it would be best to just call SendRequestAsync directly.