Cloudflare Developers

CD

Cloudflare Developers

Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news

Join

DO Placement Debugging

anyone have ideas why my DOs are being created in England (LHR) when I'm 6000 miles away in california?

Lifecycle of a Durable Object

There was a discussion around this recently. The consensus was that outgoing WebSocket connections prevented the DO from entering the "Idle, In-memory, & Hibernatable state" eventhough it's not listed as one of the three conditions that would do that in Lambros' awesome lifecycle diagram: https://developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/. I don't think we ever got a definitive answer on that thread. Someone is going to have to run an experiment.

Wanna get some thoughts on how to handle

Wanna get some thoughts on how to handle this use case: I need to synchronise a a countup timer between two types of clients. Currently, the clients poll an API which gives a datetime to signify the timer start, when field is changed then timer ticks up second by second on each client independently. Over a 30 min period these two diff client types drift up to a couple mins from each other, due to differences in how each works. If both clients were to connected to a hibernated DO WS, what would be the best way to keep a timer synced? Call an alarm() every ~1000ms and send the current time value, or continue to let each client handle on its own? Can I rely on a self-setting alarm to be 'roughly' accurate over a particular time period (for my use case, within 10 seconds drift over 30 mins would be acceptable) Not sure if this explanation makes any sense at all, I might try and make a diagram later lol...

Hey Wes. We aren't using Party Server

Hey Wes. We aren't using Party Server here; however it sounds like you are possibly awaiting the fetch result inside the realtime path. Is the await fetch() inside the onMessage handler and sibling to the broadcast() call? You should be able to resolve this by moving the fetch to another codepath or ensuring the fetch isn't blocking the broadcast....

Merging Actors and Agents

I liked the way it has some things like persistant internal vars, how it handles migrations, etc. Like I wanted to add a versioning table for my state to my agent, now I have to handle that seperatly or store things I dont want to expose in the state to the state if I want to keep it easy

Thanks for the in-depth answer! Yeah it

Thanks for the in-depth answer! Yeah it somehow doesn't add up. But good to know that the cost is miniscule. Your use case sounds pretty much like ours. Do you happen to know a pattern for DOs to handle a big number of users - think global chat or feed. I was thinking of using a DO id stored in KV that's incremented as soon as a worker receives an overloaded error so every new requests uses the next DO instance. And another KV entry that stores all active DO ids for broadcasting to all of them....

Durable object best practice

1. yes 2. should in theory be more efficient yes since the connection is established already, but it's a different topic if your app will notice this optimization 3. I believe, yes, it's charged as far as I know. Not sure if hibernation can kick in and disconnect the target. Will double check. 4. Simplicity wise, not using the RpcTarget is better if it's just doing 2 calls. But, it can be more optimized if you will be doing lots of calls and want to avoid making an RPC each time. I didn't measure the difference nowadays but I suggest measuring it and seeing if it matters to your app....

If you want to think of it as a bug feel

If you want to think of it as a bug feel free. But just keep in mind that theres 0 expectation of close events of any form running. It will generally run for the most part but not always

Single Worker with DO,RPC and rrv7 with partial prerendering

ok i wonder if that's true because it seems like they are integrating something related to RPC as well

anyone know of a better way to use a

anyone know of a better way to use a regular POJO as a durable object (sometimes). example code in thread

I try hard to design the DO parts of the

I try hard to design the DO parts of the system so that don't need any external fetches, mostly not for cost reasons but because it breaks the DO concurrency model. In the rare cases where I just couldn't design around that, I offload it to a Worker (sometimes through a Queue) who will "respond" by calling back to the DO when it has the answer. The "address" of the caller is passed along and used to get the "response" back to where it originated. JSON-RPC is really nice for this because it doesn...

I think I'd need to see what it's doing

I think I'd need to see what it's doing to make a certain answer here. If you're wanting to do it from the Worker and RPC into the DO and execute SQL you could do it like this but I also can just be 0 coffee's deep this morning and misssing the question altogether šŸ˜…
No description

using the helper:

using the helper: ```typescript export async function withSQLiteTransaction<T>( db: any,...

Not being able to track errors being

Not being able to track errors being thrown seems like not a good place to be.

json-rpc-mixin

Ummm, I am not sure about the lack of await just because of service bindings? But yes, you can get back to the DO ā€œaddressā€ either with fetch or non-callback Cloudflare native RPC. As a side note, my ā€œaddressā€ goes all of the way back to a particular browser using JSON RPC. I currently use HTTP between Cloudflare contexts but if I were building it today I would probably use Cloudflare native RPC between Cloudflare contexts. Regardless, it is WebSockets between DO and the browser using Partykit via the Agents DO base class and AgentClient in the browser....

Did that and got an error that it can’t

Did that and got an error that it can’t find the service, anyone have a boilerplate?

I'm making a service just like "uptime"

I'm making a service just like "uptime" and I want to test the website from multiple location, I want to use proxy, so I can test it from Europe/Asia/US etc, is the cf is something we can edit and tell it where it executes the request from? o0

Known issues

Is there a way to gracefully roll out a new version of a Durable Object class? It states here that objects are reset when the code is updated: https://developers.cloudflare.com/durable-objects/platform/known-issues/#global-uniqueness. In my situation, Durable Objects are pseudo-stateful, streaming an LLM call to a user. If the object resets, this LLM provider call is interrupted, and there isn't really a way to gracefully retry (apart from reperforming the LLM request itself)....

Another great thing for my use case is

Another great thing for my use case is that the old KV data will be essentially archived after this year. So I will just leave the KV namespaces as is, then create my SQL DOs as a 'v2' of my internal API
Next