https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • v

    vans163

    04/26/2021, 5:16 PM
    Theres a fun race with DOs
  • v

    vans163

    04/26/2021, 5:16 PM
    if a DO calls another DO the msgs can arrive out of order
  • v

    vans163

    04/26/2021, 5:16 PM
    so need to implement almost a TCP layer ontop of the fetch
  • v

    vans163

    04/26/2021, 5:16 PM
    with buffers/queues
  • v

    vans163

    04/26/2021, 5:17 PM
    this happens I think because of the async awaits being not scheduled in order
  • v

    vans163

    04/26/2021, 5:17 PM
    inside v8/jsruntime itself
  • v

    vans163

    04/26/2021, 5:17 PM
  • v

    vans163

    04/26/2021, 5:18 PM
    the in_progress message got delivered a few milliseconds after the done message, but the in_progress message came first.
  • v

    vans163

    04/26/2021, 5:19 PM
    there is many DO called User, where the user connect websocket to. another DO pushes update events (fetch) to the USER DO
  • v

    vans163

    04/26/2021, 5:20 PM
    if the other DO gets 3 events in order, say 1 2 3, then it pushes those events to User DO via fetch (async awaiting the fetch), the User DO may get those fetches out of order
  • v

    vans163

    04/26/2021, 5:22 PM
    i think this is due to how javascript async/await works
  • v

    vans163

    04/26/2021, 5:24 PM
    but its a tough problem, i think instead of fetching between the DOs it should be slightly more abstracted to a mailbox (like AKKA persistent mailbox, or erlang in-call-order mailbox)
  • v

    vans163

    04/26/2021, 5:25 PM
    whats happening I think is when
  • v

    vans163

    04/26/2021, 5:25 PM
    update_job comes in
  • v

    vans163

    04/26/2021, 5:25 PM
    awaiting the request body for example, causes it to possibly be scheduled before/after another status update
  • v

    vans163

    04/26/2021, 5:25 PM
    then depending on when everything arrives and what the VM decides to do, the events could go out of order
  • v

    vans163

    04/26/2021, 5:27 PM
    the fix isnt pretty but it would probably be batching requests, so there is only 1 inflight request between any 2 DOs. creating a queuelike system
  • v

    vans163

    04/26/2021, 5:29 PM
    for now il just put a session nonce on my messages and drop any status update messages out of order, maybe timestamps but i heard the DO clocks could be off by a few milliseconds between eachother
  • v

    vans163

    04/26/2021, 5:30 PM
    like DO1 clock could be 3ms ahead of DO2 clock
  • v

    vans163

    04/26/2021, 5:30 PM
    depending what hardware it spun up on
  • b

    brett

    04/26/2021, 6:07 PM
    I'm not sure I follow, since I don't know the details of what all your code is doing. A reduced code sample showing the issue might help? Generally speaking though, Workers (and Durable Objects) handle requests concurrently, as soon as the event loop is yielded (like with
    await
    ) other requests may be processed up until they, too, yield the event loop.
  • v

    vans163

    04/26/2021, 6:16 PM
    yea i think it might be storage related too and i need to use transactions
  • v

    vans163

    04/26/2021, 6:16 PM
    for atomic read/update/write operation
  • v

    vans163

    04/26/2021, 6:18 PM
    yea the msgs are arriving on the same millisecond lol
  • d

    davidbarratt

    04/26/2021, 6:18 PM
    any update on how DO will be billed for folks with Workers Bundled?
  • v

    vans163

    04/26/2021, 6:28 PM
    k it seems due to not using transactions
  • v

    vans163

    04/26/2021, 6:28 PM
    when requests arrive the way the VM seems to work on cloudflare is it ticks like x interval and pops all the fetches
  • v

    vans163

    04/26/2021, 6:28 PM
    they go into a await storage.get and both get the same value, then writeback
  • v

    vans163

    04/26/2021, 6:29 PM
    because there is no way to make the operations on storage sequential
  • v

    vans163

    04/26/2021, 6:30 PM
    Something interesting would be a compare&update that is atomic on storage to not go into a transaction
1...717273...567Latest