naia-lib / naia

a cross-platform (including Wasm!) networking library built in Rust. Intended to make multiplayer game development dead-simple & lightning-fast
Apache License 2.0
857 stars 61 forks source link

Unsafe `Send` and `Sync` implementations #154

Open mvlabat opened 1 year ago

mvlabat commented 1 year ago

The library marks a lot of types that are explicitly !Send and !Sync (meaning they can't be shared between threads) with unsafe impl Send and unsafe impl Sync. Considering that these types are actively used in the context of Bevy systems and wrapped into resources accessed with Res/ResMut, it's very likely to lead to UB.

Unsafe types in question: https://github.com/search?q=repo%3Anaia-lib%2Fnaia+%22unsafe+impl%22&type=code

We should remove all the unsafe impl Send and unsafe impl Sync occurrences, even if it means that resources can no longer be accessed from different threads. Bevy supports NonSend, and I'd argue that limiting systems to run only on the main thread is a better compromise than causing UB.

connorcarpenter commented 1 year ago

I agree, thanks for the call-out @mvlabat :+1: This may take a little bit for me to refactor though. :pray: