Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity editor hangs when losing blockchain connection. #221

Open
kilogold opened this issue Apr 9, 2024 · 4 comments
Open

Unity editor hangs when losing blockchain connection. #221

kilogold opened this issue Apr 9, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@kilogold
Copy link

kilogold commented Apr 9, 2024

Describe the bug
Unity Editor is frozen when local blockchain connection is lost.

To Reproduce
Steps to reproduce the behavior:

  1. Start local test validator.
  2. Enter Play Mode on Unity Editor.
  3. Connect to Local Net.
  4. Terminate the local test validator.
  5. [Editor Hang]

Expected behavior

  • Unity error output on lost connection.
  • Editor remains responsive.

Desktop:

  • OS: MacOS
  • Version: Ventura 13.5.1

Additional context
Unity editor version: 2021.3.32f1

@kilogold kilogold added the bug Something isn't working label Apr 9, 2024
@kilogold kilogold changed the title [Bug] Unity editor hangs when losing blockchain connection. Unity editor hangs when losing blockchain connection. Apr 9, 2024
@kilogold
Copy link
Author

kilogold commented Apr 26, 2024

I narrowed the cause of the hang to the WebSocket RPC connection.
If we disconnect from there, the main thread is not left hanging when connection to the RPC node gets interrupted.

The next thing to figure out:
How to automatically invoke a disconnection when the RPC connection is suddenly unreachable?

@kilogold
Copy link
Author

@Woody4618
Copy link
Collaborator

Woody4618 commented Apr 26, 2024

When listening to socket messages you need to switch back to mainthread before accessing any unity functions. You can do that with await UniTask.SwitchToMainThread(); @GabrielePicco would be good to add this to the subscribe function and maybe that also makes i hang?

@GabrielePicco
Copy link
Collaborator

Thanks @kilogold, definitely helpful context. On unsubscribe, there is the logic to try-reconnect (which is needed as websockets sometimes lose connection), but there could be something wrong in the handling if the rpc is unreachable. I will investigate it.
@Woody4618 you are right, this is not the intended behaviour. I opened an issue to fix it: magicblock-labs/NativeWebSocket#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants