Open JPT580 opened 8 years ago
@JPT580 looks like we need to clean up this race condition so someone is able to accurately query that /events endpoint with multiple connections. Thanks for the heads up.
This also affects the /all_events
websocket endpoint.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
No, sorry. The issue still remains. The affected code still does the same thing. See https://github.com/saltstack/salt/blob/develop/salt/netapi/rest_tornado/saltnado_websockets.py#L354
Thank you for updating this issue. It is no longer marked as stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
No, sorry. The issue still remains. The affected code still does the same thing. See https://github.com/saltstack/salt/blob/develop/salt/netapi/rest_tornado/saltnado_websockets.py#L354
Thank you for updating this issue. It is no longer marked as stale.
Looks like this is still an issue
Description of Issue/Question
When more than one websocket connection to the /events API endpoint is established, these websocket connections receive different output. According to my understanding of this endpoint, an occurring event is supposed to be delivered to all websocket connections, but instead only one of the active connections actually receives the event data.
After digging through the code i came across a part in
salt.netapi.rest_tornado.saltnado_websockets
which explains it all. When a message is received through the websocket connection from the client (which is supposed to say 'websocket client ready'), theon_message
method is invoked as a@tornado.gen.coroutine
. Within that method, this happens:Obviously, fetching the
event
like this will consume it (that event is gone for everybody else then). Any other coroutine from a different websocket connection will not be able to access that same event in order to output it.Approach to fix it
Instead of this, i would recommend to set up one coroutine that is responsible for fetching the events from the salt event bus. For each event fetched, this routine should iterate over all currently open websocket connections and feed the event data into each of them using a simple method call (or using a pipe?). This way, one could get rid of that
while True
loop and as a bonus have consistent event output across all open websocket connections.Setup
Since the code looks the same on the
master
branch, i strongly assume installingsalt
and setting it up forrest_tornado
will do.Steps to Reproduce Issue
Then simply connect to websocket clients to the
/events
endpoint ofsalt-api
and fire any event onto the bus.Versions Report for affected salt-master that runs the salt-api