Adapter life-cycle management and long-running process functionality
See original GitHub issueYou want to:
- report a bug
- request a feature
Current behaviour
- socket.io instantiates an adapter, but does not wait for a callback that it is ready. This works fine for many scenarios, but not one where the adapter needs to spool up long-running processes where the adapter is not ready to do work until they are completed. Connections from clients are handled immediately, and if you use a simple pattern of emit-on-connect from client, an early client can easily connect prior to adapter readiness.
- socket.io calls functions on the adapter, and then immediately invokes its own internal callback function with an argument of
null
. - socket.io does not notify its adapter that it is shutting down (closing). As a result, there is no opportunity to stop long-running processes within the socket or disconnect from whatever scale-out solution is being used.
Expected behaviour
- socket.io should pass a callback to the adapter constructor and wait for it to be called prior to continuing to stand up.
- socket.io should pass a callback function to adapter functions and then use that to trigger callback to the rest of the socket.io stack.
- socket.io should call a method on the adapter to indicate shutdown. It need not wait for a callback, because if shutdown fails, what are you going to do – not shut down? The in-memory adapter can simply make this function a no-op. While I haven’t reviewed the Redis adapter in enough depth to see if there is utility to this function in that adapter, I would imagine that it would be good to detach from Redis to return system resources.
Other information (e.g. stacktraces, related issues, suggestions how to fix)
This is particularly critical for the adapter that I have built that works with AWS SQS/SNS: https://github.com/thinkalpha/socket.io-sqs (socket.io-sqs on npm)
For example, actions like addAll
can’t be properly handled in time; e.g. if you addAll
a socket to room xxx and then immediately .to(xxx).emit(...)
, your message doesn’t necessarily end up back at that socket.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Processes and app lifecycle - Android Developers
This process is created for the application when some of its code needs to be run, and will remain running until it is...
Read more >Understanding Resource Adapters
Resource adapters play a central role in the integration and connectivity between enterprise information systems (EIS) and applications deployed on Oracle ...
Read more >US20020161840A1 - Adapter for interfacing with a workflow engine ...
G06Q10/10 Office automation, e.g. computer aided management of electronic mail or ... 9 is a flow chart illustrating a method for processing a...
Read more >TIBCO® Order Management - Long Running Best Practices
The best practices described in the TIBCO Order Management - Long Running Best ... issues you might encounter during the life cycle process...
Read more >Chapter 16. Java Connector Architecture (JCA) Management
JCA 1.7 was developed under the Java Community Process as JSR-322. 16.2. About Resource Adapters. A resource adapter is a deployable Java EE...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Incorporating #3661, #3660, and #3659 into this issue.
The
adapter
actually had a callback in the previous versions (included in Socket.IO v2), see here.We’ve removed it since it was not needed anymore by the Redis adapter, but it seems other adapters may benefit from this. We can add it back in the form of a Promise, would it suit your use case?
Edit: could you please merge the 3 other issues into this one please, it will be easier to follow 👼