Azure / azure-remote-rendering

SDK and samples for Azure Remote Rendering
MIT License
107 stars 39 forks source link

ARRServiceUnity.OnSessionStatusChanged and RenderingSession.ConnectionStatusChanged inconsistent callback behaviour #71

Closed WikkidEdd closed 2 years ago

WikkidEdd commented 2 years ago

We've been looking into making our unexpected disconnection handling more robust (i.e internet connection drop or server unexpectedly shutting down). To reproduce this type of scenario we've been stopping the ARR server while the client is connected via the REST API and we're seeing inconsistent behaviour of the StatusChanged callbacks.

We see 3 different behaviours with no real pattern:

  1. RenderingSession.ConnectionStatusChanged called with "ConnectionLost" followed by ARRServiceUnity.OnSessionStatusChanged with "Stopped".
  2. ARRServiceUnity.OnSessionStatusChanged called with "Stopped" (which then unregisters RenderingSession.ConnectionStatusChanged, so we don't get that call)
  3. RenderingSession.ConnectionStatusChanged only gets called "ConnectionLost", but no ARRServiceUnity.OnSessionStatusChanged callback.

I can see that 1 and 2 might occurs in a multi-threaded scenario, but 3 seems like it should never happen.

We should be able to put some workarounds for this behaviour, but thought you should know about this behaviour.

FlorianBorn71 commented 2 years ago

Hi Edd! We will revisit the callback behavior and fix inconsistencies if we find them. So thanks for additional context, that is pretty helpful! Florian

ChristopherManthei commented 2 years ago

Hi @WikkidEdd , We have looked into point 3 and there is indeed a case where ARRServiceUnity.OnSessionStatusChanged was not called but the session status was changed. This is the case if you call ARRServiceUnity.ForgetSession. A fix will go out with the next release.

In general, if you stop a session, you will inevitably end up with ConnectionLost and ARRServiceUnity.OnSessionStatusChanged eventually. The order can be a bit random as the session status is polled at regular intervals and shutting down a VM is not an atomic operation. As you already mentioned, calling ARRServiceUnity.StopSession will remove the active session in Unity and so you might miss the ConnectionStatusChanged as you no longer track an active session to begin with.

Besides this, you can hit "ConnectionLost" due to network connectivity issues which would obviously not trigger the OnSessionStatusChanged callback as the session wasn't touched (it's still in Ready state), we merely lost connection to it intermittently and a reconnect will solve the problem.

Cheers, Christopher

WikkidEdd commented 2 years ago

Thanks for the extra detail. That has helped me get a better picture in my head of what is going on.

What happens if the session status can't be polled due to connectivity. Will it just hold on to the last known session status or will it eventually change status to Unknown or Error?

ChristopherManthei commented 2 years ago

Hi @WikkidEdd, sorry for the late reply. It will remain at the last known state until a get session properties call succeeds or you explicitly call ForgetSession / StopSession. Note that if you have connectivity issues StopSession will most likely fail, and the state will continue to remain unchanged.

ChristopherManthei commented 2 years ago

Hi @WikkidEdd , we have fixed the callback inconsistency in release 1.0.57 and ARRServiceUnity.ForgetSession will now trigger ARRServiceUnity.OnSessionStatusChanged as it does change the status to unknown.