quickstart-unity icon indicating copy to clipboard operation
quickstart-unity copied to clipboard

[Bug] PutStreamAsync is never completed if there is no internet connection

Open dacodelaac opened this issue 4 years ago • 9 comments

  • Unity editor version: 2019.4.21f1
  • Firebase Unity SDK version: 7.1.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Storage
  • Other Firebase Components in use: Auth
  • Additional SDKs you are using:
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: iOS, Android
  • Scripting Runtime: Mono and IL2CPP

I am using Firebase Storage and currently having an issue using PutStreamAsync when there is no internet connection. It seems like the task will never complete, even though I reduced MaxUploadRetryTime to 1 second or got the internet connection back. Task.Status is always WaitingForActivation

var task = storageReference.PutStreamAsync(ms, new MetadataChange()
{
    CustomMetadata = GetMetaData()
}, null, CancellationTokenSource.Token);

Editor log:

ApplicationException: GetFutureStatus(handle) == kFutureStatusPending
Rethrow as ApplicationException: backing->status != kFutureStatusComplete
Firebase.Storage.StorageReferenceInternal.PutBytesUsingMonitorControllerAsync (System.IntPtr buffer, System.UInt32 buffer_size, Firebase.Storage.MetadataInternal metadata, Firebase.Storage.MonitorControllerInternal monitor_controller) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReferenceInternal.cs:148)
Firebase.Storage.StorageReference.PutBytesUsingMonitorControllerAsync (System.IntPtr buffer, System.UInt32 bufferSize, Firebase.Storage.MetadataInternal metadata, Firebase.Storage.MonitorControllerInternal monitorController, System.Threading.CancellationToken cancellationToken) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:276)
Firebase.Storage.StorageReference.PutBytesUsingCompletionSourceAsync (System.Byte[] bytes, Firebase.Storage.MetadataChange customMetadata, System.IProgress`1[T] progressHandler, System.Threading.CancellationToken cancelToken, System.Uri previousSessionUri, System.Threading.Tasks.TaskCompletionSource`1[TResult] completionSource) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:309)
Firebase.Storage.StorageReference+<PutStreamAsync>c__AnonStorey7.<>m__0 () (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:457)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ThreadHelper.ThreadStart () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)

dacodelaac avatar Apr 29 '21 08:04 dacodelaac

Hi, Thanks for creating this issue. Could you verify if this is reproducible in the Unity quickstart example for storage?

vimanyu avatar Apr 29 '21 19:04 vimanyu

@vimanyu Last time I checked, storage example still has this issue

dacodelaac avatar May 05 '21 01:05 dacodelaac

Hi @dacodelaac,

For our reproduction puposes, could you tell us which platform(s) this occurs on?

Thanks!

DellaBitta avatar May 05 '21 14:05 DellaBitta

@DellaBitta, I was using Unity Editor 2019.4.21f, targeting platform android on Windows 10 OS.

dacodelaac avatar May 07 '21 13:05 dacodelaac

Hi @dacodelaac,

I attempted to reproduce this with the Storage Test App using Upload Stream with airplane mode enabled on and Android device. I'm getting an retry limit exceeded exception as expected. I tested with Firebase Unity SDK 7.2.0.

Steps taken:

  • Launch App
  • Enable Airplane mode on the device.
  • Scroll down through the test app and set Max Operation Retry Time and Max Upload Retry Time to 1000, or 1 (I tried both).
  • Click on Upload Stream.

Note that the storage location configuration in the test app isn't important since we're squelching the network request.

Could you update these steps to cause a reproduction of the issue? Thanks.

DellaBitta avatar May 10 '21 14:05 DellaBitta

Hi @DellaBitta,

I tested with Unity Editor 2019.4.21f, on Windows 10, target platform Android, Firebase Unity SDK 7.2.0

Step:

  • Launch app
  • Sign in successful
  • Try Upload Stream a few times to check if it works.
  • Disable internet adapter
  • Try Upload Stream again, get an exception ApplicationException: GetFutureStatus(handle) == kFutureStatusPending, and the upload task will never be completed even if you enable the internet adapter. That why I cannot get retry limit exceeded exception because the task looks like it running forever.

dacodelaac avatar May 10 '21 14:05 dacodelaac

Hi @dacodelaac ,

Can you verify whether you're seeing the issue when running in the Unity editor (pressing the play button) or on a physical Android device?

Thanks --Patrick

patm1987 avatar May 10 '21 20:05 patm1987

@patm1987 ,

I can still reproduce this issue on Unity Editor

  • Disable internet adapter
  • Press play button
  • Press Upload Stream
  • See exception (I think it is normal because we don't have internet connection)
System.AggregateException: One or more errors occurred. ---> Firebase.Storage.StorageException: The server did not return a valid JSON response.  Contact Firebase support if this issue persists.
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Storage.StorageException: The server did not return a valid JSON response.  Contact Firebase support if this issue persists.<---

UnityEngine.Debug:Log (object)
Firebase.Sample.Storage.UIHandler:DebugLog (string) (at Assets/Firebase/Sample/Storage/UIHandler.cs:114)
Firebase.Sample.Storage.UIHandler:DisplayStorageException (System.Exception) (at Assets/Firebase/Sample/Storage/UIHandler.cs:211)
Firebase.Sample.Storage.UIHandler/WaitForTaskCompletion:get_keepWaiting () (at Assets/Firebase/Sample/Storage/UIHandler.cs:174)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
  • Press Upload Stream again
  • Exception:
ApplicationException: GetFutureStatus(handle) == kFutureStatusPending
Rethrow as ApplicationException: backing->status != kFutureStatusComplete
Firebase.Storage.StorageReferenceInternal.PutBytesUsingMonitorControllerAsync (System.IntPtr buffer, System.UInt32 buffer_size, Firebase.Storage.MetadataInternal metadata, Firebase.Storage.MonitorControllerInternal monitor_controller) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReferenceInternal.cs:148)
Firebase.Storage.StorageReference.PutBytesUsingMonitorControllerAsync (System.IntPtr buffer, System.UInt32 bufferSize, Firebase.Storage.MetadataInternal metadata, Firebase.Storage.MonitorControllerInternal monitorController, System.Threading.CancellationToken cancellationToken) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:276)
Firebase.Storage.StorageReference.PutBytesUsingCompletionSourceAsync (System.Byte[] bytes, Firebase.Storage.MetadataChange customMetadata, System.IProgress`1[T] progressHandler, System.Threading.CancellationToken cancelToken, System.Uri previousSessionUri, System.Threading.Tasks.TaskCompletionSource`1[TResult] completionSource) (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:309)
Firebase.Storage.StorageReference+<PutStreamAsync>c__AnonStorey7.<>m__0 () (at Z:/tmp/tmp.0Ryilsblb3/firebase/storage/client/unity/proxy/StorageReference.cs:457)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Threading.ThreadHelper.ThreadStart () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)
  • Then, you cannot press Upload Stream anymore because the previous task is not completed.

PS: Just tested it on my phone, this issue did not exist.

dacodelaac avatar May 11 '21 01:05 dacodelaac

I can confirm that I see this with the storage quickstart. MacOS host. Android target. Running in the Unity Editor. Unity 2021.1.3f1. Storage SDK 7.2.0.

The first time I upload I get a normal exception that's handled appropriately. The second time it hangs with kFutureStatusPending and fails to continue even after re-establishing networking connectivity.

I'm going to mark this as a bug but as something that only shows up in the Editor. If you see it on device (Android/iOS phone/tablet) as well, let us know as it may effect prioritization!

patm1987 avatar May 11 '21 23:05 patm1987