Photon stuck disconnecting? Unable to reconnect

I'm currently trying to setup a method for players that have been disconnected from the server to reconnect,
however I'm having an issue where Photon stays in a 'disconnecting' state.
Because of this I'm never able to reconnect as it sends me the error
"ERROR: Cannot connect to Photon while Disconnecting. Connection failed.
NetworkingPeer:Connect(String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:186)
PhotonNetwork:Connect(String, Int32, String, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1022)
<ConnectToBestRegionInternal>c__Iterator11:MoveNext() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PingCloudRegions.cs:150)
PingCloudRegions:ConnectToBestRegion(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PingCloudRegions.cs:58)
PhotonNetwork:ConnectToBestCloudServer(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:950)"
I'd greatly appreciate any help regarding this as it's really frustrating and I haven't been able to find any information on it.


  • Hello,

    Probably Connect() is called right after Disconnect(). Disconnection is not done immediately, so in this case Photon is always in disconnecting phase during the call. Connect again only after the status will change to Disconnected.
  • No I actually have it waiting until it has reached disconnection status and isn't only disconnecting,
    I know that it doesn't disconnect immediately. The problem is it never disconnects fully.
    I've tried reconnecting it after 5 minutes just to check if it wasn't checking the disconnection correctly,
    but even then it told me it couldn't reconnect as it was disconnecting.
  • If you want to reconnect, you can't use ConnectToBestRegion in the second attempt. Keep the region you initially get.
    It's odd that you are in state "disconnecting", when you say you try to re-connect after a timeout. After a timeout you usually get into state disconnected.

    I would check if you do some connect or disconnect somewhere where you didn't expect it. Maybe in OnEnable or something. These methods can cause calls to Connect even when you don't expect it.
    It would help to know how you came into this state. Can you send a complete log with the "ALL" debug level?
  • Thanks a lot for your response.

    I greatly appreciate that information on ConnectToBestRegion as I hadn't heard anything like that at all mentioned anywhere, which will help save 1 headache when I hopefully solve this stuck in disconnecting issue.

    Here's the full log from starting the project to when it gets stuck in the disconnecting state

    Originally what I was trying to do was after having players set their photon App ID,
    if it was incorrect to then take them back for another chance to input the correct App ID.
    However it would act like it was connected but actually lose the connection, so I would wait a moment to recheck the connection, and if it was no longer connected I would wait for it to completely disconnect, however it wasn't doing that.
    I thought when you mentioned it's method of disconnection might have been a problem that if I manually told it to disconnect after a successful connection with the right App ID, it might disconnect then, however even after doing that it still won't lose its 'disconnecting' status and becomes stuck.
  • As workaround, call:

    At the moment I'm a bit clueless how this state issue happens.
    If you can, export your project or a smaller repro case, upload somewhere for me to download and send me a link to that package along with a description how to reproduce the issue.
  • Regrettably that is no better either, it still stays in a disconnecting state.

    I tried looking about and was wandering if this might be the issue?
    "Assets/Photon Unity Networking/Plugins/PhotonNetwork/SocketUdpNativeDllImport.cs(138,25): warning CS0219: The variable `state' is assigned but its value is never used"
    Note: I'm using the latest version of PUN+
    Might it not be getting/updating the state correctly because of this?

    I'm not sure if I would be able to export the project for you to try out because of its usage of playmaker, unless you have that? Either way thanks for the thought, hopefully a resolution might be found through the above issue and a possible solution. (I hadn't originally thought of it as a problem because of it connecting correctly, etc).
  • That warning is not an issue. It's simply a variable we don't use in this case, I think.

    It could be related to PUN+ actually. It seems that PUN (the higher level) actually understands that it disconnected while maybe the level below might be stuck in the Disconnecting state.

    It's unfortunate that StopThread didn't help. Can you send me another log where you call that? If it works, it should call "OnStatusChanged(StatusCode.Disconnect)" and I would like to see why it doesn't. Right now, from the code, I can't see why it shouldn't work.

    I think, your can't call connect in OnStatusChanged(StatusCode.Disconnect) / OnDisconnectedFromPhoton! That callback is done before (!) the Disconnected state is set (which can be the cause of the issue).
  • Thanks for your response :), sorry for my delay in replying-I worked on other things for a bit before coming back to this.

    Ahh thank you for clarifying, I'm never quite sure when warnings are actually effecting something or not.

    Here's a log where I call StopThread

    The problem isn't trying to reconnect too quickly, I have it waiting for its status to be properly changed to disconnected before trying to reconnect, however it never reaches that stage. And I've also left it for 5 minutes+ before manually forcing it to check the state again but it's still disconnecting even after that amount of time. I've also of course done all the miscellaneous things like resetting unity/computer/etc in-case it's something weird like that and it's the latest compatible versions of each plugin so that isn't the issue either. I really hope you're able to find something in the latest log, thanks again for your time with this.
  • This is a very late reply (sorry for that).
    Do you still have this issue?
    We are going to roll out a new server version in the next weeks which should fix stuck players on the server. Hopefully that's doing it for you.
Sign In or Register to comment.