fetch() sometimes returning 520 even though request to origin was successful

Using a database API via a non-standard port (I cannot test it with a standard port) sometimes returns a 520 status code even though the request actually succeeded. As far as I can tell, the origin database is actually sending back a 200 response, that cloudflare is somehow turning into a 520 before it reaches the worker. I've ran through basically every analytic I can measure and I haven't been able to figure out why only a very small portion of requests are just failing. Any insight would be much appreciated 🙏 I've also reviewed that the third-party server is not: - Sending headers > 16 KB - Blocking Cloudflare IPs
3 Replies
louiek22
louiek22OP2mo ago
Additional notes: we're using standard placement, so I don't think the old bug applies. Solved it somehow. I stopped using the Clickhouse SDK and instead made the requests from scratch myself. It took a bit of work. In addition to making the requests myself I had to compress the request body. No 520s after I started compressing the body. Here's the compression function I user:
const compress = async (
str: string,
encoding = "gzip" as "gzip"
): Promise<ArrayBuffer> => {
const byteArray = new TextEncoder().encode(str)
const cs = new CompressionStream(encoding)
const writer = cs.writable.getWriter()
writer.write(byteArray)
writer.close()
return new Response(cs.readable).arrayBuffer()
}
const compress = async (
str: string,
encoding = "gzip" as "gzip"
): Promise<ArrayBuffer> => {
const byteArray = new TextEncoder().encode(str)
const cs = new CompressionStream(encoding)
const writer = cs.writable.getWriter()
writer.write(byteArray)
writer.close()
return new Response(cs.readable).arrayBuffer()
}
cc @Chaika, I think you'll find this interesting. And thanks for pointing me in the right direction with mentioning that you use the HTTP api directly!
Chaika
Chaika2mo ago
That is interesting, I wonder what the clickhouse SDK was doing differently
louiek22
louiek22OP2mo ago
It wasn't compressing the request body. It was literally that one change that fixed it. I recreated the same requests the SDK did, byte-for-byte and then just compressed the body For context on volume: this was 300 req/s pushing an average of 30 rows
Want results from more Discord servers?
Add your server