Slow requests in Workers

For Workers & Pages, what is the name of the domain?

api.vskaraokes.app

What is the issue or error you’re encountering

Slow requests

What are the steps to reproduce the issue?

Some of my users are having a curious problem: my worker, which is accessible through my domain on Cloudflare, takes about 300 seconds to respond to the request. That is: I send the request through my C# program via HttpClient and the request is only completed after about 300 seconds. I discovered this because my HttpCLIENT TimeOut was the default of 100 seconds and I was getting the “TimedOut” error. So, I set my TimeOut to 500 seconds and, surprisingly, the requests were completed after 200 seconds. I have no idea why this is happening. The worst part is that in Chrome, when I access my Worker through the domain as a normal user, it loads instantly. However, using HttpClient in C#, it takes 250 to 300 seconds to respond to the request. In CMD, if I ping the worker’s domain, it also returns a timeout. In the “nslookup” test in the Windows cmd everything is normal. I think there may be some blocking by Cloudflare. I accessed the Worker through C# both through my custom domain and through the workers.dev domain and it’s the same thing.

Can anyone give me some light on this?

There could be many reasons why your requests to a Worker would time out. Perhaps you’re hitting an API in your worker that’s very slow to respond?

Without a lot more information about what you’re doing in your worker, some code to reproduce the slowdowns, etc. we can only speculate on why things may be slower than you expected.

1 Like

In fact, my Workers code is quite simple: it only makes one query to a database with about 2000 rows. The average execution time of my Workers on the Cloudflare dashboard is like 20ms, so I dont think thats the problem. I think it might be a problem with the user’s route or ISP.

If your browser is working faster than more “raw” connections, my guess is that it’s a slow-down as CF doesn’t trust your connections from CLI/App. As there’s less HTTP header data being sent it looks more like a bot than a human and CF WAF could be making the response wait [so it wastes the bots time].

I’d add a unique key to your query (in the URL or HEADERS) and then add a security rule on CF Dashboard to ignore any security checks on your specific requests.

It makes sense. But where in the Workers panel are there configurable security functions? I looked and didn’t find anything like that.

Workers are called after the many aspects of the TLS/CDN/Proxy and other rules effect a request. Quite a few of those could be affecting the speed of your response.

You’ll see Workers are a long way down on this screenshot from within the Rules section of the Dashboard:

I suggest looking into using the new Trace tool to see how it affects your function:

It could also not be Bot/Authenticity related.

Modern web browsers can normally do TLS1.3 (with caching/resume), HTTP3 & compression, inc a local cache - which, unless specified, won’t be done on your other 2 clients. These all effect speed/latency.

I really can’t find these waf rules options, etc. for workers. There are only these options for custom domains registered in my Cloudflare account. However, these domains are not necessarily being used to access Workers via GET. Through Cloudflare Trace, it goes directly to the Worker, as shown in the attached image.

Do you have any idea why?

Oh - so you’re not putting your CF enabled domain infront/aliasing the Worker; then in that case you don’t get to control these other layers… you’re affected by however the “workers.dev” service operates.

But I believe you should move away from calling a “workers.dev” domain directly - not only will you get more control, I think CF explicitly state that you shouldn’t use it for production purposes (it’s meant as a shortcut to get you up and testing your worker without too much configuration).

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.