socketioxide icon indicating copy to clipboard operation
socketioxide copied to clipboard

Hold a per `Client` state rather than a static state.

Open Totodore opened this issue 1 year ago • 1 comments

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.

Totodore avatar May 06 '24 18:05 Totodore

If someone want to contribute for this issue:

  • Move the state typemap to the Client struct and add a clone bound.
  • Pass the typemap to each handler.
  • Clone the extracted state from the typemap in the extractor.

Totodore avatar May 08 '24 13:05 Totodore