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

    vans163

    07/27/2021, 6:47 PM
    seems it throws if awaiting it
  • v

    vans163

    07/27/2021, 6:47 PM
    tho i rather not block awaiting it yea i think overall this wont work in the end and websockets will be required
  • v

    vans163

    07/27/2021, 6:47 PM
    or nm i could do a .then()
  • j

    john.spurlock

    07/27/2021, 9:58 PM
    I'm curious if data stored via the DO storage api is irrevocably deleted when 1) the javascript class is no longer associated with the DO namespace using the rest api or 2) when the DO namespace is deleted using the rest api
  • s

    Subh

    07/28/2021, 6:47 PM
    Hey team! Are there more examples for DO? I saw the game example and a chat example.
  • w

    Wallacy

    07/28/2021, 9:30 PM
    In think when in delete the DO, using api, wrangler or whatever every data associate is lost. Thats why im planing a scheduled backup....
  • j

    john.spurlock

    07/28/2021, 9:32 PM
    Yea just curious in when exactly we should expect to lose all the associated data, when the namespace is modified to point to another class? when the namespace is deleted? when the script is deleted? or something else?
  • w

    Wallacy

    07/28/2021, 9:37 PM
    I’m assuming that is everytime that we use —delete-class.
  • j

    john.spurlock

    07/28/2021, 9:39 PM
    yea but that that wrangler command calls multiple cloudflare rest api calls behind the scenes (I don't use wrangler, call the apis directly) - curious which one actually means the data is no longer available after that.
  • v

    vans163

    07/28/2021, 10:40 PM
    Is there any work or ideas for inorder delivery of messages between DOs?
  • v

    vans163

    07/28/2021, 10:40 PM
    currently if 1 DO sends to another DO, the receiver DO can get all out of order
  • v

    vans163

    07/28/2021, 10:40 PM
    which makes me kinda wanna just open Websockets between DOs instead of do fetches
  • v

    vans163

    07/28/2021, 10:52 PM
    I have a problem with BYOB buffer stream reader
  • v

    vans163

    07/28/2021, 10:52 PM
    it seems the DO is unable to process IO while there is a loop running
  • v

    vans163

    07/28/2021, 10:55 PM
    really really weird
  • v

    vans163

    07/28/2021, 10:59 PM
    is it possible to get a DM to explain the issue? basically if I can write it out in pseudocode its like this..
    Copy code
    javascript
    async fetch(request) {
        if (request.headers.get("Upgrade") == "websocket") {
          let pair = new WebSocketPair();
          var websocket = pair[1];
          var session = {websocket: websocket, last_ping: Date.now()};
          this.sessions.push(session);
    
          websocket.accept();
          websocket.addEventListener("message", async msg=> {
            session.last_ping = Date.now();
          });
    
          return new Response(null, { status: 101, webSocket: pair[0] });
        }
    
        if (request.method === "POST" || request.method == "PUT") {
            const { readable, writable } = new TransformStream()
            const reader = readable.getReader({ mode: "byob" })
            request.body.pipeTo(writable)
    
            await this.constantly_read_body(reader)
    
            return new Response("", {status: 200});
        }
        return new Response("oops", {status: 400});
    }
    
    async constantly_read_body() {
        while(1) {
            send_message_to_do_2("ping");
            send_msg_to_websocket("ping");
    
            const { value, done } = await reader.read(this.buffer);
            if (done)
              break;
        }
    }
    basically as long as constantly_read_body fetch request is running (even tho it breaks on the await), no IO is sent out the DO if that IO originates on the same fetch request context. send_message_to_do_2("ping"); send_msg_to_websocket("ping"); Both get queued up. As soon as the fetch dies (say I kill it manually), the queue starts flushing and do_2 as well as connect websocket get a flood of msgs. Note I can connect 5+ websockets while the fetch is running, its just the websockets dont get any msgs that originate (if the caller is) from the fetch request. The actual accept happens.
  • v

    vans163

    07/28/2021, 11:04 PM
    Seems the bug is kinda "All IO that originates from a fetch request if no new Response is sent gets queued up until a Response is sent"
  • v

    vans163

    07/28/2021, 11:05 PM
    im gonna try something, and set the other end to a new TransformStream() reader
  • v

    vans163

    07/28/2021, 11:12 PM
    no luck it seems to be even more busted doing this
    Copy code
    const { readable2, writable2 } = new TransformStream()
            return new Response(readable2, {status: 200});
  • d

    Deleted User

    07/29/2021, 1:07 PM
    can DO classes be anonymous classes (constructed inside a function)? considering they're assigned to a const
  • b

    brett

    07/29/2021, 1:46 PM
    Only when the namespace itself is actually deleted. Rebinding to a different class is what we'd call a "migration" and the entire purpose (as far as I know) is to keep the underlying data while you swap out the code implementation.
  • b

    brett

    07/29/2021, 1:49 PM
    Hmm, I haven't tried, but they need to exported from the module
  • z

    zifera

    07/29/2021, 1:49 PM
    Im a little bit confused why you have to make fetch requests to do something on a DO. What if you want to run any specific code on a DO that should not be available to anyone else. Do you have to write "fake" fetch requests in your backend.
  • z

    zifera

    07/29/2021, 1:51 PM
    Lets say I have a simple counter and I want to read the total value of the counter in my backend somewhere. I have to create something like fetch('/counter/total') and read the value in the DO and get the value. It feels a bit strange to me.
  • b

    brett

    07/29/2021, 1:51 PM
    What do you mean by a fake request? Remember that a DO instance is running in one location in the world. So a client worker in the USA and EU both have to send messages to talk to it, it isn't just code that runs inside the client worker.
  • j

    john.spurlock

    07/29/2021, 1:52 PM
    Thank you, that makes sense. So the data would be available if you renamed the class and updated the existing namespace - that's useful. I've noticed that while you can initially create a namespace without a script/class, once defined it does not seem like you can set the script/class to undefined or null again, is this intentional?
  • b

    brett

    07/29/2021, 1:53 PM
    Yeah it's to prevent people from accidentally breaking their production DO namespace by deleting the underlying worker (for example)
  • b

    brett

    07/29/2021, 1:54 PM
    You could migrate to a no-op class if you really wanted to break things
  • z

    zifera

    07/29/2021, 1:54 PM
    Or do you have to see the DO as an API located somewhere else. And if you want to do anything with it you have to call a specific endpoint. If you want to protect it, add and API key or some other form of protection. Im now just mainly calling it from the same worker script i created the DO class in.
  • j

    john.spurlock

    07/29/2021, 1:55 PM
    hmm, can multiple namespaces point to the same script+class? like a noop class
1...133134135...567Latest