Fix hang if app deactivated before server started and first navigate
Includes next commits from 3-5-stable:
475c3547c01f29fe58d241ecfef575c26c50384b
43258f6dd1f31a404880168ad081dbc3e579ef5a
ad600443ec3d25ecdbc52bc7f112c30235f8fe11
d17b53340ca7e6739bd704ad0cf5f2581d5cf6c5
a00e7fc71ff12024e2dbe04db2fbdc8fc4cd7868