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

Ensure rejected connections are not stored - which causes memory leaks #34

Conversation

mjeffrey18
Copy link
Contributor

Background

I found a memory leak in production due to unathorised connections still being stored on the Cable::Server#connections hash.

Screenshot 2021-10-21 at 21 24 23

Implementation

  • Add reject_connection! helper methods to connection class and use this to ensure rejected connections are never added to the Cable::Server#connections hash
  • Ensure connection identified_by(field) can be used with a different key other than identifier while still providing access via connection.identifier
  • Refactor connect.reject(channel : Cable::Channel) to instead support connection.reject(payload : Cable::Payload) keeping it consistent with the other methods like subscribe, unsubscribe and message
  • Refactor some of the macros and unused mock methods from the connection class to make it more readable - Shout out to @jgaskins as this was taken from his fork.
  • Update readme to show users how to reject channel subscriptions

Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
- to avoid memory
- also some minor syntax cleanup

Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
Copy link
Collaborator

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing stuff! Thanks so much for taking this on. It's a pretty big PR, so I want to make sure I really go over it. I left a few suggestions, but only real change I think is to just leave the version alone for now. Otherwise I'm open to your input on the other things.

src/cable.cr Outdated Show resolved Hide resolved
src/cable/connection.cr Outdated Show resolved Hide resolved
src/cable/connection.cr Outdated Show resolved Hide resolved
src/cable/monkeypatch/redis.cr Show resolved Hide resolved
src/cable/connection.cr Outdated Show resolved Hide resolved
Signed-off-by: Marc Jeffrey <mjeffrey18@gmail.com>
@@ -1,84 +1,54 @@
require "uuid"

module Cable
class Connection
abstract class Connection
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense. What do you think @fernandes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, totally, specially because this class should never get instantiated itself.. way better! 👍

Copy link
Collaborator

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I dig it!

@mjeffrey18 mjeffrey18 closed this Nov 11, 2021
@mjeffrey18 mjeffrey18 reopened this Nov 11, 2021
Copy link
Collaborator

@fernandes fernandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's awesome! thank you @mjeffrey18 !

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

Successfully merging this pull request may close these issues.

None yet

3 participants