resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
685 stars 67 forks source link

Service response to call not chronological with events #14

Closed jirenius closed 6 years ago

jirenius commented 6 years ago

Issue

If a service receives a request (eg. call.userService.user.42.set) which triggers an event (eg. event.userService.user.42.change) before sending the call response, the call response might arrive to the client prior to the event, even if they were sent from the service in the opposite order.

Cause

The issue is caused by call responses being passed directly from the message system (mq) goroutine to the connection (wsConn) queue, while all get-responses and events are passed from the mq goroutine to the eventSubscription's queue before being passed to the connection (wsConn) queue.

Solution

Call responses should be passed to the eventSubscription's queue to ensure all calls and events are handled by the same go routine. The eventSubscritpion worker will then directly passes on to the response to the connection (wsConn) queue.

jirenius commented 6 years ago

Fixed in https://github.com/jirenius/resgate/pull/19 Also improved http status codes.