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

Compatibility and memory footprint issues with @SocketSession decorator #2394

Closed
derevnjuk opened this issue Jul 26, 2023 · 2 comments · Fixed by #2395
Closed

Compatibility and memory footprint issues with @SocketSession decorator #2394

derevnjuk opened this issue Jul 26, 2023 · 2 comments · Fixed by #2395
Assignees

Comments

@derevnjuk
Copy link
Contributor

Information

  • Version: 7.x
  • Packages: @tsed/socketio

The @tsed/socketio library utilizes in-memory session storage allowing injecting the session data through @SocketSession decorator. However, this implementation is not compatible with socket.io adapters and the connection state recovery feature. Additionally, this approach can cause a growing memory footprint over time, which may impact the application's performance and stability.

To address the compatibility and memory footprint concerns, the usage of the @SocketSession decorator should be reworked. Instead of relying on in-memory session storage, the decorator should be modified to inject the value of socket.data, preserving backward compatibility with existing SocketIO implementations.

Example

@SocketService("/my-namespace")
export class MySocketService {
  $onConnection(@Socket socket: SocketIO.Socket, @SocketSession session: SocketSession) {
    if (socket.recovered) {
      // recovery was successful after the server crash, rolling update, etc
      console.log(session.get('key1')); // outputs value1
    } else {
      // new or unrecoverable session
      session.set('key1', 'value1');
    }
  }
}
@github-actions
Copy link

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.34.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants