Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions do not maintain ordering #460

Open
jkxyz opened this issue Jun 6, 2024 · 3 comments
Open

Subscriptions do not maintain ordering #460

jkxyz opened this issue Jun 6, 2024 · 3 comments
Assignees
Milestone

Comments

@jkxyz
Copy link

jkxyz commented Jun 6, 2024

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.

@hlship hlship self-assigned this Jun 12, 2024
@hlship
Copy link
Member

hlship commented Jun 12, 2024

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?

@jkxyz
Copy link
Author

jkxyz commented Jun 12, 2024

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.

@hlship hlship added this to the 1.3.0 milestone Jun 29, 2024
@hlship
Copy link
Member

hlship commented Jun 29, 2024

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.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants