box / box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5

Home Page:https://developer.box.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request Timeout might not work if WiFi connection was off

23W opened this issue · comments

  • I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
  • I have checked that the [API documentation][api-docs] doesn't solve my issue.
  • I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
  • I have searched [Issues in this repo][github-repo] and my issue isn't already reported.

Description of the Issue

When application starts download some relatively big file (around 8Mb) from Box and WiFi connection has been lost or switched off at this moment, timeout exception will never raise and application hangs

Steps to Reproduce

  1. Run download operation client.FilesManager.DownloadAsync()
  2. Wait 2 seconds and switch off WiFi connection
  3. See error

Expected Behavior

After timeout period (around 100 sec), timeout exception must be thrown

Screenshots

image

App Example for test:

            string ClientId = "my-client-id";
            string ClientSecret = "my-secret-id;
            string RedirectUri = "https://my-redirect-uri.com/";

            var refr = "my-refresh-token;
            var acs = "my-access-token";
            var session = new OAuthSession(acs, refr, 3600, "bearer");

            var config = new BoxConfig(ClientId, ClientSecret, new Uri(RedirectUri));
            var client = new BoxClient(config, session);

            Console.WriteLine($"Start download {DateTime.Now}");

            try
            {
                var FileId = "my-file-id";

                using (var fileStream = new FileStream("MyFile.bin", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read, bufferSize: 4096, useAsync: true))
                using (var stream = await client.FilesManager.DownloadAsync(FileId))
                {
                    await stream.CopyToAsync(fileStream, 4096);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e.Message}");
            }

            Console.WriteLine($"End download {DateTime.Now}");

Versions Used

Box SDK: 4.4.0
.Net SDK: .Net Framework 4.7.2; .Net 6.0
Windows: 10

I see you create HttpClient with infinite timeout (method ClientFactory.CreateClient()):

                var client = new HttpClient(handler)
                {
                    Timeout = Timeout.InfiniteTimeSpan // Don't let HttpClient time out the request, since we manually handle timeout cancellation
                };

I don't think it's a good idea.

Hi @23W,
thanks for submitting this Issue! We will take a look and get back to you ASAP!
@lukaszsocha2

Hi @23W ,
you can set this timeout when building a config:
var config = new BoxConfigBuilder(ClientId, ClientSecret, new Uri(RedirectUri)).SetTimeout(TimeSpan.FromSeconds(100)).Build();
It should cause timeout also with no internet connection. Hope this solves your issue.
Best,
@lukaszsocha2

@lukaszsocha2
Thank you, i'll check but why default timeout doesn't work?
Another question: does not this BoxConfig's timeout stop downloading big file to early? I mean that HttpClient timeout works only when client waits response.

Hi @23W , you can set this timeout when building a config: var config = new BoxConfigBuilder(ClientId, ClientSecret, new Uri(RedirectUri)).SetTimeout(TimeSpan.FromSeconds(100)).Build(); It should cause timeout also with no internet connection. Hope this solves your issue. Best, @lukaszsocha2

Nope, It didn't help
image
It's been about 300 seconds, but there's no timeout exception.

commented

This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

commented

This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box .NET SDK and feel free to open another PR/issue at any time.