socketioxide
socketioxide copied to clipboard
Hold a per `Client` state rather than a static state.
Currently the global state management is done with a static state. It is convenient because the user can put non clonable data and get a 'static ref from any callback. However this should be completely avoided for the following reasons:
- With multiple clients spawned, their are going to share the same state and this will probably lead to bugs. First example with all the integration tests for the socketioxide lib.
- Currently the implementation uses unsafe code to do this. Moving to a per client clonable state remove this.
- This will lead to a possible axum-like state implementation. Having only one typed state rather than the type erased
typemap.
If someone want to contribute for this issue:
- Move the state typemap to the
Clientstruct and add a clone bound. - Pass the typemap to each handler.
- Clone the extracted state from the typemap in the extractor.