adonisjs / transmit

A Server-Sent-Event module for AdonisJS
MIT License
57 stars 3 forks source link

[question] - How to Delete Open Channels Created by Clients in Transmit? #27

Closed joaosilva0345 closed 4 weeks ago

joaosilva0345 commented 1 month ago

Package version

1.0.2

Describe the bug

Hi, I understand that channels are created as soon as clients subscribe to them. However, I would like to know how I can delete channels that have been opened by clients. Is there a built-in way to handle this, or would I need to implement a custom solution?

Thank you for your assistance!

Reproduction repo

No response

joaosilva0345 commented 1 month ago

I may have created this issue incorrectly. I'm new to this and still learning how to use GitHub properly. If this question doesn't belong here, feel free to delete it.

RomainLanz commented 1 month ago

Hey @joaosilva0345! 👋🏻

This could be easily automated.

When a client disconnects, we can check if another client is still in the channel. If not, we delete the channel internally. What do you think?

thetutlage commented 1 month ago

Aren't channels memory only? If yes, what's the purpose of deleting it? Because a channel with zero connected clients will be an empty object/set inside memory and will consume only few bytes.

RomainLanz commented 1 month ago

Aren't channels memory only? If yes, what's the purpose of deleting it? Because a channel with zero connected clients will be an empty object/set inside memory and will consume only few bytes.

Because even if it is only a small string in memory, an attacker may create millions of them if no security is added to the Transmit endpoint. This could cause a security risk in the long run.

I don't believe deleting the entry will create any issue.

joaosilva0345 commented 1 month ago

When a client disconnects, we can check if another client is still in the channel. If not, we delete the channel internally. What do you think?

Yes, it might be a good idea.

Sorry for the delay in replying.

joaosilva0345 commented 1 month ago

Because even if it is only a small string in memory

If I understand correctly, even with Redis configured as a transport, the channels are still kept in local memory in each server instance, and Redis is only used to synchronize the state of the channels between different instances. Is this correct?

RomainLanz commented 1 month ago

Hey @joaosilva0345! 👋🏻

After rewatching the codebase, the channel names are not stored anywhere. They are directly linked to a subscriber (stream). When the stream ends, this relation is deleted, too.

Therefore, there is no need to delete anything manually.

Redis is only used to synchronize the state of the channels between different instances

Correct.