Skip to content

Subscriptions do not maintain ordering #460

@jkxyz

Description

@jkxyz

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions