return 522 using fetch in a worker to request api of another worker

When a worker requests the api under the domain name bound by another worker, 522 is returned. "The initial connection between Cloudflare's network and the origin web server timed out". But at the same time, the api of the worker accessed can be accessed normally on the public network.
https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_522&utm_campaign=4tr.cc
https://www.cloudflare.com/5xx-error-landing?utm_source=errorcode_522&utm_campaign=4tr.cc
. the error page shows i can find more info here but results of
Cloudflare protects this website. But, something went wrong trying to reach it
Cloudflare protects this website. But, something went wrong trying to reach it
2 Replies
jhd
jhd9mo ago
solved by using service binding
Chaika
Chaika9mo ago
Nice, Service bindings are indeed the correct way to solve this. The underlying reason is Same zone (domain) Worker Requests will bypass the other worker and try to use the non-existent origin behind the worker. If they are on a different zone, the worker request will invoke the other worker properly. more full explanation & reasoning: https://community.cloudflare.com/t/issue-with-worker-to-worker-https-request/94472/8?u=chaika