Download file API timeout via Box sdk
Hi Guys,
I am working on sync file from box to another source. Almost 3 weeks ago, we found there are lots of download file API timeout issue was occured in our production. I am try to print the error log.
~~~ json
"@t": "2022-03-18T08:37:13.1328496Z",
"@mt": "ExternalContentSync BoxApiWrapper ExecuteBasicRequest exception {@Detail}",
"@l": "Error",
"Detail": {
"AbsoluteUri": "https://api.box.com/2.0/files/932716620970/content?Range=bytes=0-62272",
"Message": "A task was canceled.",
"StackTrace": " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at Box.V2.Request.HttpRequestHandler.<ExecuteAsync>d__2`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Box.V2.Services.BoxService.<ToResponseAsync>d__4`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Nuage.Common.External.ExternalContentV3.ApiClients.BoxApiClient.ExecuteRequest[T](IBoxRequest request) in c:\\users\\seismic\\workspace\\ines_cap-library_release_release\\Common.External\\ExternalContentV3\\ApiClients\\Box\\BoxApiClient.cs:line 116\r\n at Nuage.Common.External.ExternalContentV3.Wrappers.BoxApiWrapper.ExecuteBasicRequest[T](IBoxRequest request) in c:\\users\\seismic\\workspace\\ines_cap-library_release_release\\Common.External\\ExternalContentV3\\Wrappers\\BoxApiWrapper.cs:line 363"
}
~~~
this is our code to use the Box sdk
~~~ C#
private Stream BoxExecuteBasicRequest(string fileId, long startByte, long endByte)
{
Stopwatch stopWatch = Stopwatch.StartNew();
var url = string.Format("https://api.box.com/2.0/files/{0}/content?Range=bytes={1}-{2}", fileId, startByte, endByte);
IRequestHandler handler = new HttpRequestHandler();
var service = new BoxService(new HttpRequestHandler());
try
{
BoxRequest boxrequest = new BoxRequest(new Uri(url));
boxrequest.Timeout = TimeSpan.FromSeconds(1200);
var responseResult = service.ToResponseAsync<Stream>(boxrequest).GetAwaiter().GetResult();
if (responseResult.Status == ResponseStatus.Success)
{
return responseResult.ResponseObject;
}
else
{
return this.ResponseErrorHandler<string>(boxrequest, responseResult);
}
}
catch (Exception ex)
{
stopWatch.Stop();
LogFactory.GetLogger(LogType.ExternalContent).Error(
"ExternalContentSync BoxApiWrapper ExecuteBasicRequest exception {@Detail}, Request duration {requestDuration} ms", new
{
url,
ex.Message,
ex.StackTrace
}, stopWatch.ElapsedMilliseconds.ToString());
throw;
}
}
~~~
We were change the timeout to 1200 seconds in BoxRequest object, but we still occured the timeout issue, and request was pended 1200 seconds.
~~~ json
"@t": "2022-03-18T12:45:55.9677376Z",
"@mt": "ExternalContentSync BoxApiWrapper ExecuteBasicRequest exception {@Detail}, Request duration {requestDuration} ms",
"@l": "Error",
"Detail": {
"AbsoluteUri": "https://api.box.com/2.0/files/932718617698/content?Range=bytes=0-26969",
"Message": "A task was canceled.",
"StackTrace": " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Box.V2.Request.HttpRequestHandler.<ExecuteAsync>d__2`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Box.V2.Services.BoxService.<ToResponseAsync>d__4`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at Nuage.Common.External.ExternalContentV3.ApiClients.BoxApiClient.ExecuteRequest[T](IBoxRequest request) in c:\\users\\seismic\\workspace\\ines_cap-library_release_release\\Common.External\\ExternalContentV3\\ApiClients\\Box\\BoxApiClient.cs:line 117\r\n at Nuage.Common.External.ExternalContentV3.Wrappers.BoxApiWrapper.ExecuteBasicRequest[T](IBoxRequest request) in c:\\users\\seismic\\workspace\\ines_cap-library_release_release\\Common.External\\ExternalContentV3\\Wrappers\\BoxApiWrapper.cs:line 366"
},
"requestDuration": "1200010",
~~~
Could you please help us?
-
Hey Paul,
There couple be lots of reasons for this...
Do you have the client id for the Box application you created in the developer console? The enterprise ID of your instance would be helpful too.
Also. To confirm - you are using this sdk?
-
Hey Alex,
Thanks for your support! Below is the info as what you need. Yes, we are using the Box SDK version of Box.V2.3.9.0\lib\net45\Box.V2.dll
ClientId: t2emajg79ngqew344begko6rn4n6y5hj
User ID: 215448143 Enterprise ID: 434601And more context here, we have the background service to read file content from client box server based on their OAuth configuration. Due to improve the file download performance, we will create 5 threads to download different files in parallel. For each individual file downloading, We will use the range stream approach to download, each range stream block size is 10MB. Will this approach cause the Box download api timeout issue? Does Box server side have the max concurrent connections limitation or similar threshold limitation? And what's the right direction to resolve this kind of issue in our application?
Thank you!
-
Hello,
Apologies on the delay... our dev forum is not manned for urgent on-demand support. If you would like immediate support - you would need to have a business or above license and contact our support group.
From what I'm seeing - the app created has an OAuth 2.0 authentication type... it also looks like it doesn't have the scopes added to run as-user calls (allows you to see other content that the authenticated used isn't collaborated in). Based on the error logs, it looks like both files you are trying to download are owned by a different user... is the user_id 215448143 collabed into the files you are trying to download?
Thanks,
Alex
-
Hey Alex,
Thanks for the update! Yes, we are using OAuth authentication type, and using the mapped user credential to access the file, who granted the access permission in the authentication process. So the customer user should have the permission to access the file. The user_id 215448143 here should be registered in the Box develop console for app recognition.
In my understanding, if there no permission to access the file, the Box api response should be 403 forbidden something like that, but not timeout response. How do you think? Could you please help with any insights further?
Thank you!
Post is closed for comments.
Comments
5 comments