Subscriptions do not maintain ordering
jkxyz opened this issue · 3 comments
I've been using Lacinia subscriptions to handle AWS event stream responses, to stream those events back to the client.
It seems that the values passed to the subscription callback function are not sent to the WebSocket in the same order that the callback is called. I can log the order on the server, and then by observing the WebSocket messages I can see that they're being sent in a different order.
Here's a stripped down version of the subscription handler:
(defn subscription-handler [_context _args callback]
(let [cancel-ch (async/chan)
events-ch (async/chan)
fut
(future
(invoke-model-stream events-ch ,,,))]
(async/go-loop []
(async/alt!
cancel-ch nil
events-ch ([event]
(callback event)
(when event
(recur)))))
(fn []
(async/close! cancel-ch)
@fut)))
It doesn't seem to be documented anywhere that Lacinia subscriptions don't provide ordering guarantees. For now I've managed to work around this by providing an index in the responses and re-ordering on the client.
I'm surprised that order is not maintained, I'll have to look over the code and the guarantees made by core.async. How close are the events from AWS coming in?
How close are the events from AWS coming in?
I've been testing this with the InvokeModelWithResponseStream operation on the AWS Bedrock API. So the events are coming in milliseconds apart. The rate is not constant and most events do arrive on the client in the correct order.
I can provide more surrounding code to try and get a minimal reproduction, if it helps.
I'm putting this on a milestone just to keep track of it, I haven't looked at it at all (to verify, to reproduce it, etc.).