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

UploadAsync sometimes throws Exception after file was uploaded

ChristianGalla opened this issue · comments

Description of the Issue

BoxClient.FilesManager.UploadAsync sometimes throws an exception after a file was successfully uploaded to Box.

Steps to Reproduce

  1. Upload some files that are currently not in Box using BoxClient.FilesManager.UploadAsync
  2. If an Exception is thrown, retry the upload

Expected Behavior

No Exception is thrown if a file was successfully uploaded to Box exclusive or an Exception is thrown and the file was not uploaded to Box.

Error Message, Including Stack Trace

Example 1

Error on first attempt:
System.TimeoutException: Request timed out ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Request.HttpRequestHandler.<getResponse>d__7.MoveNext()
   --- End of inner exception stack trace ---
   at Box.V2.Request.HttpRequestHandler.<getResponse>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Request.HttpRequestHandler.<ExecuteAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Services.BoxService.<ToResponseAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxResourceManager.<ExecuteRequest>d__12`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxResourceManager.<ToResponseAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadAsync>d__7.MoveNext()
Error on retry:
Box.V2.Exceptions.BoxPreflightCheckConflictException`1[Box.V2.Models.BoxFile]: {"type":"error","status":409,"code":"item_name_in_use","context_info":{"conflicts":{"type":"file","id":"XXXX","file_version":{"type":"file_version","id":"XXXX","sha1":"XXXX"},"sequence_id":"0","etag":"0","sha1":"XXXX","name":"XXXX"}},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Item with the same name already exists","request_id":"XXXX"}
   at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
   at Box.V2.Managers.BoxResourceManager.<ToResponseAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadAsync>d__7.MoveNext()

Example 2

Error on first attempt:
Box.V2.Exceptions.BoxException: The API returned an error [BadGateway]
   at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
   at Box.V2.Managers.BoxResourceManager.<ToResponseAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadAsync>d__7.MoveNext()
Error on retry:
Box.V2.Exceptions.BoxPreflightCheckConflictException`1[Box.V2.Models.BoxFile]: {"type":"error","status":409,"code":"item_name_in_use","context_info":{"conflicts":{"type":"file","id":"XXXX","file_version":{"type":"file_version","id":"XXXX","sha1":"XXXX"},"sequence_id":"0","etag":"0","sha1":"XXXX","name":"XXXX"}},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Item with the same name already exists","request_id":"XXXX"}
   at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
   at Box.V2.Managers.BoxResourceManager.<ToResponseAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadAsync>d__7.MoveNext()

Versions Used

.Net SDK: 3.24.0
Windows: Server 2012 R2

Possible Workaround (not tested)

When an application is using the SDK and an Exception on file upload is thrown, the application should call a pre flight check before an upload is retried.

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.