johanhelsing / matchbox

Painless peer-to-peer WebRTC networking for rust wasm (and native!)
Apache License 2.0
848 stars 67 forks source link

bevy_ggrs example is broken #417

Closed AgustinRamiroDiaz closed 4 months ago

AgustinRamiroDiaz commented 5 months ago

What

The example under examples/bevy_ggrs is broken.

How to reproduce

  1. git clone https://github.com/johanhelsing/matchbox
  2. cd matchbox/examples/bevy_ggrs
  3. cargo run
  4. See error
    2024-02-17T14:34:05.377797Z  INFO bevy_ggrs_example: connecting to matchbox server: "ws://127.0.0.1:3536/bevy_ggrs?next=2"
    2024-02-17T14:34:05.377909Z DEBUG log: Starting WebRtcSocket    
    thread 'main' panicked at /home/az/dev/matchbox/matchbox_socket/src/webrtc_socket/socket.rs:477:33:
    called `Result::unwrap()` on an `Err` value: Closed
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    Encountered a panic in system `bevy_ggrs_example::lobby_system`!
    Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

Additional context

johanhelsing commented 4 months ago

I've been digging into this issue, and it goes away if the example is built with the bevy multi-threaded feature.

When digging, I also found the following:

WebRtcSocket::try_update_peers returned Err(ChannelError::Closed) even though the channel was neither dropped, nor closed. So it looks like a bug in futures_channel::mpsc::UnboundedReceiver, that it's not behaving as documented, though that seems somewhat unlikely. I'm not sure what to think.

In any case, the workaround is to add multi-threaded to the bevy features. Perhaps we should add it as a requirement for bevy_matchbox as well...