Stuck in PeerCreated state

Options
Harris
Harris
Hello all,

We're working on a multiplatform (web/ios/android) multiplayer game which has been working fine until a few weeks now. Once it get disconnected due to internet issue or staying in background for long it gets into PeerCreated state where .isConnected is false, and we cannot execute Disconnect(), ReconnectAndRejoin() and Reconnect().

I've searched the internet and the forum for my the issue and have tried some of the solutions, but since we have a small user base we cannot use ConnectToBestPhotonCloud, we need to place our users in the same region.

What is PeerCreated State?

What should we be doing in PeerCreated State?
1. Diconnect (what are ways to do it?)
2. Reconnect (what is the correct way to do it?)

What are other solutions we can have?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Harris,

    Thank you for choosing Photon!

    I did the same as you, a search on the forum (keyword = "PeerCreated") and found few related discussions.

    First of all, we need the PUN version you are using and where you noticed this "issue".

    Do you implement PUN callbacks for disconnection and connection failures?
    Could you add logs for the different client states and helper properties in those callbacks?
    Something like:
    PhotonNetwork.connectionStateDetailed
    PhotonNetwork.connectionState
    PhotonNetwork.connected
    PhotonNetwork.connecting
    And callbacks:
    void OnConnectionFail(DisconnectCause cause);
    void OnDisconnectedFromPhoton();
    void OnFailedToConnectToPhoton(DisconnectCause cause);
  • Harris
    Options
    We're using latest version of PUN (1.87),

    We're logging Detailed Connection State variable and log level is set to max for photon and Debugger. So we get a lot of logs. Most of the game play, connect reconnect work fine, it only gets stuck when we're on PeerCreated state.

    Not much is done in OnConnectionFail Disconnect, and FailedToConnect on photon other than logging the cause. I'll look into detail for what can be done there.

    After visiting the Disconnection Cause I think it will be
    one or both of the following:
    DisconnectByServerTimeout = StatusCode.DisconnectByServer,
    DisconnectByClientTimeout = StatusCode.TimeoutDisconnect,

    But since we're not totally disconnected (but .isconnected is false), and we cannot execute Disconnect in this state. How shall we reconnect in the above scenario? I'll debug and get more info from these callback.
  • Harris
    Options
    Hi,

    This issue is still pending, When we are in a room and application disconnects in background, it doesn't get reconnected and remains in PeerCreated mode.

    ReconnectAndRejoin(), Rejoin(), ConnectUsingSettings(), and Disconnect() do not work since we are neither connected nor disconnected. Is there a RESET module callback?

    Steps to produce:

    On an iOS device:
    ConnectUsingSettings();
    ConnectToLobby();
    CreateRoom();

    Once in room, send app to background for some time, so that it gets disconnected.

    Maximize the app and try to reconnect, the game will stay stuck in PeerCreated mode for a indefinite amount of time, and will require few restarts or killing/relaunching the app.
  • jeanfabre
    Options
    Hi,

    Can you tell me which Unity version you are using, and I'll try to reproduce.

    - what kind of room do you create, does it feature emptyroomTtl or PlayerTtl?

    - how do you check you are disconnected and are you calling ConnectusingSettings again or ReconnectAndRejoin?

    I'll run some tests meanwhile.

    bye,

    Jean
  • jeanfabre
    Options
    Hi,

    I can confirm that on my end this is working fine. I published the demos as is from a fresh project on Unity 5.6 on IOS, ran the demoBox, went into background, waited 30 seconds, back to the app indeed status is PeerCreated. I click Connect and it connects fine again.

    So, we'' need more info on how exactly you reconnect and on which version of Unity you are publishing with in order to get closer to a resolution for your case.

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    also, which version of Pun are you using. there was a bug around this and it was fixed in v1.85 so make sure you have the latest version.

    Bye,

    Jean
  • Harris
    Harris
    edited January 2018
    Options
    Hi,

    Thanks for the replies, they helped a lot. We're already at 1.87 but PeerCreated state is still an issue.
    We tried a lot of stuff in to get out of PeerCreated state after resuming after 30-40 minutes.

    Out game is live at the moment, and was banner featured for a week as well, but photon's reconnect issues are really affecting since reconnection isn't reliable.

    However we tried following and got out of this state, now we'll be pushing an update this week.

    Launch app, send the app to background for some time, resume, if Photon Network is stuck in PeerConnected and there's no way to get out of it, Try following

    PhotonNetwork.offline = true;
    //wait for some time.
    PhotonNetwork.offline = false;
    //wait for some time.
    PhotonNetwork.Disconnect(); //now the game will finally perform disconnect.

    and at times, it doesn't restart at this point. There's a protected method DisconnectToReconnect() which changes networkingpeer.state to Disconnecting, this sometimes help. Cause of disconnection mostly is ClientTimeOut or ServerLogic or ServerTimeOut

    Suggestions are welcome.

    Regards.
  • Atif
    Atif
    edited January 2018
    Options
    Hi @jeanfabre and @JohnTube

    Me are Harris (thread initiator) are from same team. Our game is Gems Frontier (available on iTunes and Play Store). Its a 1-1 match-3 realtime RPG.

    Since Photon does not support direct message passing to a user. We are using Photon rather unconventional way. In our game a user always stays in its own room, so that we can send message to any user. We need this message passing for some game features like challenge requests. When a match has to start, one of the user lefts his room and join others room and after match he lefts the match room and creates its own room again (so that he can listen requests from his friends).

    And sometime Photon stuck in Peer connected state when user try to resume game after a long pause and we try to connect to Photon.

    Is it possible that the above scenario, creates some exception in Photon and in rare conditions Photon stuck in peer created state indefinitely?

    I know you will suggest to use Photon Chat or similar services. But we want to avoid overhead of another SDK. It would have been great if Photon provides basic functionality like sending challenge request to a user.

    Thanks and regards,
    Atif
  • jeanfabre
    Options
    Hi,

    Indeed, the way to go is using both the Chat Sdk and Pun. I know this means two connection, but this is not a problem really, it actually allows both pun and the chat sdk to connect players the best way possible and in the most effective way, hence why The chat system is separate, it uses dedicated servers with specific service settings to be very efficient at communicating across a large player pool, while Pun cloud servers are optimize to be very efficient at sending large amounts of data to a specific room, two very distinct connection needs, calling for specific server settings to reduce cost and increase efficiency.

    your way is not unconventional at all, many games made with photon use your system, connecting players in rooms ( 16 max) acting as lobby where they can communicate, but again it has limitation and only in certain game play and connection scenarios, indeed with chat you will be able to call ANY time ANY one for help to win a game or for just playing and chating, it is overall way more powerful.

    as for your peer created state, no I don't think it is related to your usage at all. We did experiment some issues overall the last few days, so if this only started to occur, chances are this is already fixed, else can you contact support and we'll take it from here ( you can mention me, ticket will be redirected to me and we look at your issue).

    Bye,

    Jean

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Atif @Harris

    I think maybe the issue is caused by the background thread on Android.
    Can you confirm that this issue is on Android only?
    Can you change PhotonNetwork.BackgroundTimeout value and see if the PeerStuck happens if you exceed that duration while in the background?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Options
    after re reading the old posts I think it's rather an iOS issue and we're talking about 30-40 minutes of background time and not 60 seconds.
    no clues now...
  • Atif
    Options
    Thanks @JohnTube and @jeanfabre,

    We will look for Photon chat solution.
    JohnTube said:

    after re reading the old posts I think it's rather an iOS issue and we're talking about 30-40 minutes of background time and not 60 seconds.
    no clues now...

    We are facing this issue on both platforms and yes normally when the app is in background for more than 30 mins. You can install the game and experience it.

    Again thanks for the prompt response. Hope we will reach to the cause of the problem soon.

    Regards,
    Atif

  • jeanfabre
    Options
    Hi,

    ok, I'll try again and publish on IOS and see how it behaves, I'[ll get back to you on my findings tomorrow.

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    ok, I'll try again and publish on IOS and see how it behaves, I'll get back to you on my findings.
    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    ok, I can't repro this. when you go in the Bg and back after long enough, yes, you have been disconnected and you are in peerCreated mode, but clicking connect works, I get connected again.

    Maybe you could provide a minimal repro case, if I can repro, then I can have a look at what exactly needs to be done in your case.

    Bye,

    Jean
  • Harris
    Options
    Thanks for the support JeanFabre, we'll debugging and refactor the controller, and see if we can eliminate it.