Leaked Connection Causes Unity to Freeze

Options
I was having issues with the Unity editor completely locking up after a play session for a few weeks. Basically if a connection is left open and then the editor either compiles or you attempt to play again, it will freeze up and have to have the process terminated.

This was an extremely difficult bug to figure out without being able to debug the editor itself, and I only managed to figure it out on accident. I was cleaning up the regular server connection fine, but forgot to disconnect on destroy for the chat server.

It would be nice if PUN cleaned itself up properly and perhaps just reported an error message in the event that the connection was leaked.

What I really don't understand though is why a leaked connection would freeze the main thread.

EDIT:
My suspicion is that the garbage collector goes after the open connection and something happens there. Unfortunately, it is closed source at that level, and I can't delve further into it. Perhaps ChatPeer/PhotonPeer needs a finalizer?

Comments

  • Tobias
    Options
    I noticed this (mis)behaviour, too, but so far I didn't have a proper idea how to fix this, aside from making sure to disconnect properly when the App quits.
    I tried a finalizer and it seems to improve things, so this will be in the next version of PUN.
    Thanks for the report and analysis. And sorry for the hassle.
  • Dan7
    Options
    There is a solution for this? after upgrading to Unity 5 I'm having this problem, after make a connection the editor stops responding, this problem is killing me, I have to end the process.
  • Tobias
    Options
    As said, I made our socket classes IDisposable and it seems to have a good effect versus the freezing. As it's so random, I can't promise a 100% fix though and I also don't test all Unity versions (there are too many by now, as the patch releases make good progress almost every week).
  • Teddymac
    Options
    I dug this one up because I am having this exact issue. I am building for mobile and I want to know what is the best practice to prevent this from happening. Should you use the OnDestory method to disconnect from Chat or the OnApplicatioinQuit. Or is there some better way now to prevent this?

    Tobias mentioned that there isn't a 100% fix back in 2015. I am using Unity 2017 1.1f1.

    Also, is this just an Unity Editor issue? Or will these freezes happen on mobile devices as well if Chat isn't properly shut down?