socketio / socket.io-aws-sqs-adapter

The Socket.IO adapter for AWS Simple Queue Service (SQS), allowing to broadcast events between several Socket.IO servers.
https://www.npmjs.com/package/@socket.io/aws-sqs-adapter
MIT License
4 stars 1 forks source link

[Update] clean related topic and subcription base on process exit eve… #1

Closed kidnextdoor461993 closed 4 months ago

kidnextdoor461993 commented 5 months ago

Update event listeners to clean backlogged subscriptions and topics on development environment. In cases:

  1. App crashed.
  2. User terminate app by Ctrl + C.
darrachequesne commented 5 months ago

Thank you for your interest in this new adapter!

However, I think this should be handled by the end user, and not by the adapter itself. What do you think?

kidnextdoor461993 commented 5 months ago

Thank you for your interest in this new adapter!

However, I think this should be handled by the end user, and not by the adapter itself. What do you think?

I think if we allow the end user to decide this we should provide full both info of [queueUrl] and [subscriptionArn] on result of createAdapter function. Currently I just see _topicArn property on createAdapter result, so this is missing the way help end user decide delete or keep queue and subscription of current session. There is an example where the system is running and encounters some error and crashes the application. Then the server's registered service tries to restart your application and fails again, and so on, the startup loop is endless until you log in to your AWS Console account and see Hundreds of thousands of queues and subscriptions are created, which is a cost nightmare for AWS services.

darrachequesne commented 5 months ago

AWS Console account and see Hundreds of thousands of queues and subscriptions are created, which is a cost nightmare for AWS services.

Sorry for that. The cleanup.sh script in the repository may help clean up these subscriptions...

I think if we allow the end user to decide this we should provide full both info of [queueUrl] and [subscriptionArn] on result of createAdapter function.

Can't you just call io.close() (or io.of("/").adapter.close() for version < 4.7.5)?

process.on("SIGINT", () => {
  io.close();
});   
kidnextdoor461993 commented 5 months ago

Can't you just call io.close() (or io.of("/").adapter.close() for version < 4.7.5)?

process.on("SIGINT", () => {
  io.close();
});   

I called and subscription and queue still not remove on AWS SNS. Currently I see the core don't have any call to clean them!! Screenshot 2024-03-23 at 01 52 32

darrachequesne commented 5 months ago

The queue is removed here when the isClosed variable is set to true:

https://github.com/socketio/socket.io-aws-sqs-adapter/blob/0ee1d4c0ff7cb238ae661e909a3f6dc603cdbc39/lib/index.ts#L195-L219

That being said, we could indeed cancel the current poll(), as the receiveMessage() method accepts an abortSignal option. What do you think?