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

    ckoeninger

    03/16/2023, 3:15 PM
    if you want worker B's MY_DO binding to refer to worker A's implementation of MyDO, your binding in worker B's wrangler.toml needs to look like
  • c

    ckoeninger

    03/16/2023, 3:16 PM
    bindings = [{ name = "MY_DO", class_name = "MyDO", script_name = "whatever-worker-A-script-name-is" }]
  • r

    Ryan The Temp

    03/16/2023, 3:17 PM
    is "script_name" refer to the name of the worker?
  • c

    ckoeninger

    03/16/2023, 3:17 PM
    yeah
  • c

    ckoeninger

    03/16/2023, 3:18 PM
    like the first line of the wrangler.toml for worker A probably has a
    name = "worker-a"
    line or equivalent
  • r

    Ryan The Temp

    03/16/2023, 3:19 PM
    I'm trying that now
  • r

    Ryan The Temp

    03/16/2023, 3:19 PM
    thx for the suggestion
  • r

    Ryan The Temp

    03/16/2023, 4:07 PM
    Related to the above, I maybe have gotten to use the same DO, but I'm unable to test it. I'm basically using the DO to be able to track connected websockets in a kind of publisher/consumer. So: Worker A receives a stream ---Durable Object --- storage = [websocket1, websocket2] -----------------------
    Worker B
    Consumes a stream from
    Worker A
  • r

    Ryan The Temp

    03/16/2023, 4:08 PM
    When a websocket connects to
    Worker B
    , I save that socket connection in the DO
    Copy code
    ts
    await this.storage.put('ref', webSocket)
  • r

    Ryan The Temp

    03/16/2023, 4:10 PM
    But for some reason, If I change the above to:
    Copy code
    ts
    webSocket.send('this executes')
    await this.storage.put('ref', webSocket)
    webSocket.send('this line never executes')
    does something happen behind the scenes from the await call that prevents the execution of the next line?
  • c

    ckoeninger

    03/16/2023, 4:22 PM
    I'm not clear on what benefit you're trying to get from putting a websocket in durable storage - even if it was serializable, getting it out of storage later after a DO was evicted from memory wouldn't somehow re-establish network connections from the client
  • h

    HardAtWork

    03/16/2023, 4:23 PM
    Would be cool to be able to store WebSockets in a way that allows you to persist it even if a DO is evicted
  • r

    Ryan The Temp

    03/16/2023, 4:23 PM
    What I'm trying to build is a relay: Client streams data - to worker -> worker relays that data to a connected client.
  • r

    Ryan The Temp

    03/16/2023, 4:26 PM
    What I thought that I can do is have to workers: - Worker A: To receive data - Worker B: To stream data I thought that I can use a DO to keep track of clients that are connected to Worker B so that Worker A can stream to those clients whenever they connect
  • c

    ckoeninger

    03/16/2023, 4:30 PM
    https://github.com/cloudflare/workers-chat-demo/blob/master/src/chat.mjs#L401
  • d

    Dani Foldi

    03/16/2023, 4:31 PM
    I'd love to see this with hibernated websockets, so we don't cause a flood of reconnects if we push a new deployment to the worker - possibly not even changing the DO code.
  • c

    ckoeninger

    03/16/2023, 4:33 PM
    so after multiple code pushes you would expect to have an arbitrary number of versions of your DO code running simultaneously, based only on which instances happened to end all open websocket connections at a given time? That sounds really hard to reason about
  • h

    HardAtWork

    03/16/2023, 4:36 PM
    According to the docs PR, looks like it should do that natively
  • h

    HardAtWork

    03/16/2023, 4:36 PM
    Though I’m wondering if it can persist between
    workerd
    releases…
  • d

    Dani Foldi

    03/16/2023, 4:41 PM
    Is a hibernated websocket still linked to the specific deployment of a DO class?
  • d

    Dani Foldi

    03/16/2023, 4:41 PM
    My idea was that hibernated websockets can wake up in a new version of a DO if there is one since it was hibernated
  • c

    ckoeninger

    03/16/2023, 4:43 PM
    What language in the docs PR is leading you to infer that?
  • c

    ckoeninger

    03/16/2023, 4:45 PM
    What would your expectation be if the new version of the DO has changed how it handles the data in WebSocket.attachment
  • d

    Dani Foldi

    03/16/2023, 4:45 PM
    Hmm, I guess migrations would be overkill to "version" handlers, so not sure really
  • c

    ckoeninger

    03/16/2023, 4:47 PM
    If the main concern is flood of reconnects, would an option to increase the time for all DOs to reset after a code update not address that concern?
  • d

    Dani Foldi

    03/16/2023, 4:48 PM
    It definitely would if the deployment can define if evicting old DOs is an immediate priority or can be done anytime
  • h

    HardAtWork

    03/16/2023, 4:49 PM
    This would be with the hibernation API, but that still counts as Native, no?
  • c

    ckoeninger

    03/16/2023, 4:53 PM
    Thanks, I can see why that's confusing
  • c

    ckoeninger

    03/16/2023, 4:54 PM
    We are definitely not intending to guarantee that hibernation keeps websockets connected across code updates (whether it's your code or runtime restarts)
  • h

    HardAtWork

    03/16/2023, 4:55 PM
    I get that there isn’t a guarantee on that a WS is persisted, but is there a chance that it may stay up?
1...521522523...567Latest