Randomly worker requests are being canceled

Hi 👋 ! We have a Cloudflare worker (with two environments) that accepts PATCH requests and makes update requests to Baserow. I suddenly noticed yesterday the worker is canceling the requests without throwing any kind of errors. Everything works fine tills a fetch request is made. Sometimes the code works, so I'm confused if the worker is hitting any time limit. Note: 1. Changing the custom domain URL and changing it back somewhat fixes the issue. Sometimes the requests get canceled but the fetch request goes through. Sometimes the fetch request goes through without canceling the request. 2. Setting workers_dev to true somewhat fixes the issue too. Sometimes the requests get canceled but the fetch request goes through. If I set it to false again, sometimes it keeps working, sometimes it doesn't. Code: https://github.com/dilmaheu/dilmahtea.me-workers/blob/main/src/workers/dilmahtea-me-baserow/src/index.ts
GitHub
dilmahtea.me-workers/src/workers/dilmahtea-me-baserow/src/index.ts ...
Contribute to dilmaheu/dilmahtea.me-workers development by creating an account on GitHub.
9 Replies
Isaac McFadyen
Isaac McFadyen•15mo ago
This is happening because you're not reading the body of the fetch request. The workaround is to read the body but to do nothing with it.
// Read the body but discard it.
await response.text()
// Read the body but discard it.
await response.text()
Muhymin
MuhyminOP•15mo ago
Interesting! Let me notify you after trying it @Isaac McFadyen | YYZ01 I tried it but reading the body doesn't fix the issue Doing further investigation, I found that the request can get canceled even before reading the value from the KV database in https://github.com/dilmaheu/dilmahtea.me-workers/blob/main/src/workers/dilmahtea-me-baserow/src/index.ts#L59C62-L59C65
Alp
Alp•15mo ago
You maybe hit the cpu time limits. You can see that on the cloudflare dashboard; Workers > your worker > Metrics tab > Error tab at the bottom. There is a legend Exceeded CPU Limits shows this kind of errors. Also you can try changing your workers usage model to Unbound from Bundled if it is Bundled
Muhymin
MuhyminOP•15mo ago
The worker is already on the Unbound usage model. And no we are not hitting any CPU limits The metrics tab shows 100% success rate. It seems canceled requests do not count as errors. @Isaac McFadyen | YYZ01 though your solution didn't solve this issue, could you please explain why not consuming the response body can cause the worker to be canceled??
Isaac McFadyen
Isaac McFadyen•15mo ago
It's an internal optimization of the Workers runtime (workerd). If a response body is not consumed, then it's ignored which speeds things up but also may cause issues with the Worker getting cancelled. Unsure, might be fixed now. We used to see that happen sometimes, anyway.
Muhymin
MuhyminOP•15mo ago
Interesting 🤔 @Isaac McFadyen | YYZ01 since the requests are sometimes getting canceled even before making the fetch request, what do you think the issue can be??
Isaac McFadyen
Isaac McFadyen•15mo ago
I'm unsure, sorry. Sometimes a request can be cancelled if a person actually cancels the request (navigates away, hits Control + C with cURL, closes the tab or browser) so that might be it?
vas
vas•8mo ago
Hi, Does changing a worker's Usage model in cloudflare worker dashboard incur downtime or is it only applied to new instances of that worker?
Isaac McFadyen
Isaac McFadyen•8mo ago
This is an unrelated thread, please open a new one if you have a different question.
Want results from more Discord servers?
Add your server