docusign-esign-csharp-client icon indicating copy to clipboard operation
docusign-esign-csharp-client copied to clipboard

Timeout/Fail Issue when calling Client Functions

Open chasse20 opened this issue 10 months ago • 2 comments

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:

https://github.com/docusign/docusign-esign-csharp-client/blame/master/sdk/src/DocuSign.eSign/Client/SystemNetHttpClient.cs#L35

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.

chasse20 avatar Feb 12 '25 20:02 chasse20

TemplatesApi.GetAsync method doesn't go through the SendRequest method, but the SendRequestAysnc method(https://github.com/docusign/docusign-esign-csharp-client/blob/3aa9f59abdd9973e8d193581b19ba6b081199be8/sdk/src/DocuSign.eSign/Client/SystemNetHttpClient.cs#L45) instead.

I've tested the TemplatesApi.GetAysnc method but the response was returned without issue. I would recommend creating a support case to troubleshoot this issue further so we can share the details of your API call in the private thread. Please share the network logs when you create the support case so we can troubleshoot further. Here's the link to open the support case with DocuSign: https://support.docusign.com/s/articles/How-Do-I-Open-a-Case-in-the-DocuSign-Support-Center?language=en_US

ByungjaeChung avatar Feb 13 '25 01:02 ByungjaeChung

Thank you,

I was wrong and looking at the wrong function for some reason.

The issue I'm observing is that seemingly every so often the HTTP request call is running indefinitely. The most at fault has been the TemplatesApi.GetAsync. I'll be collecting a lot more logs this week to hopefully observe this issue again (or will spam unit tests) and more accurately pinpoint it. A Cancellation Token passed down the entire chain would still be highly desirable to better manage retrying and failures. Right now I cannot cancel the attempt even if I detect a timeout.

For context, we use the ESign library within our backend API in support of a custom sales frontend. It's been optimized for running thing asynchronously without the user via JWT Grant. This runs as a Durable Azure Function.

chasse20 avatar Feb 13 '25 02:02 chasse20