You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
workerd/jsg/util.c++:274: error: e = kj/compat/tls.c++:221: failed: TLS peer's certificate is not trusted; reason = Hostname mismatch
Therefore, following the miniflare documentation, I set up a serviceBinding to create a worker that invokes a Node.js function. This works well, but at a certain scale it triggers a miniflare or workersd error: Network connection lost.
Reproduction:
main.ts
import {Miniflare, Request, Response, Headers} from 'miniflare';
async function EXTERNAL_FETCHER(request: Request): Promise<Response> {
try {
const res = await fetch(request.url);
const respHeaders = new Headers(res.headers);
respHeaders.delete('Host');
respHeaders.delete('Content-Length');
return new Response(res.body, {status: res.status, headers: respHeaders});
} catch (e) {
return new Response(`EXTERNAL_FETCHER error: ${(e as Error).toString()}`, {status: 500});
}
}
const mf = new Miniflare({
scriptPath: 'worker.mjs',
https: true,
modules: true,
serviceBindings: {
EXTERNAL_FETCHER,
},
});
try {
const res = await mf.dispatchFetch('http://localhost:8787');
console.log(await res.text()); // Expected: Hello Miniflare!
} catch (e) {
console.error(e);
}
await mf.dispose();
worker.mjs
export default {
async fetch(_request, env) {
const buffers = [];
for (let i = 0; i < 100; i++) {
const response = await env.EXTERNAL_FETCHER.fetch(new Request(
`https://abc.xyz.workers.dev?r2Key=${i}`
));
const buffer = await response.arrayBuffer();
buffers.push(buffer);
}
const uint8Arrays = [];
for (const buffer of buffers) {
const arr = new Uint8Array(buffer);
uint8Arrays.push(arr);
}
for (let i = 0; i < 100; i++) {
const response = await env.EXTERNAL_FETCHER.fetch(new Request(
`https://abc.xyz.workers.dev?r2Key=${i}`
)); // first call fails with Error: Network connection lost.
}
return new Response('Hello Miniflare!');
},
};
Explanation:
The cloudflare worker URLhttps://abc.xyz.workers.dev is fake, but when I use my real worker URL it returns binary content of approximately 300kb for each fetch request.
The Network connection lost. error is raised during the the first fetch call in the second for loop. This does not appear to be related to the number of fetch calls that are made, but rather, the size of uint8Arrays. By simply breaking out of the loop that pushes items onto uint8Arrays after 23 iterations, the code works without issues. However, if it reaches 24 iterations, the next subsequent fetch call will fail with the reported error.
Exploration:
This does not appear to be related to Node.js memory limits. After raising the node memory limit to 16gb with the max-old-space-size flag, it continues to fail at the same point.
It works as expected when run outside of miniflare/workersd, with node, deno, and bun, by replacing await env.EXTERNAL_FETCHER.fetch with a fetch call, as these other runtimes support https.
It also works inside of miniflare/workersd by changing the url from http to https, but this is not ideal for my use case, which requires providing an auth token in the URL.
Hypothesis:
My best guess is that this issue is related to either a workersd memory or a bound worker connection time limit. It seems like, at some point the connection to the bound worker is dropped, and after a predefined timeout, the Network connection lost. error is returned.
Please provide any relevant error logs
No response
The text was updated successfully, but these errors were encountered:
Which Cloudflare product(s) does this pertain to?
Miniflare
What versions are you using?
3.20241106.0 [Miniflare], v18.20.4 [Node.js]
What operating system and version are you using?
Ubuntu 20.04.6 LTS
Please provide a link to a minimal reproduction
No response
Describe the Bug
Error occurs when a miniflare worker makes a
fetch
request to a worker that is bound viaserviceBindings
.Problem I am trying to solve:
I want to make a https request using the built-in workersd
fetch
function, like so:but it fails with this error:
Therefore, following the miniflare documentation, I set up a
serviceBinding
to create a worker that invokes a Node.js function. This works well, but at a certain scale it triggers a miniflare or workersd error:Network connection lost.
Reproduction:
main.ts
worker.mjs
Explanation:
https://abc.xyz.workers.dev
is fake, but when I use my real worker URL it returns binary content of approximately 300kb for each fetch request.Network connection lost.
error is raised during the the firstfetch
call in the secondfor
loop. This does not appear to be related to the number offetch
calls that are made, but rather, the size ofuint8Arrays
. By simplybreak
ing out of the loop that pushes items ontouint8Arrays
after 23 iterations, the code works without issues. However, if it reaches 24 iterations, the next subsequent fetch call will fail with the reported error.Exploration:
max-old-space-size
flag, it continues to fail at the same point.await env.EXTERNAL_FETCHER.fetch
with afetch
call, as these other runtimes support https.http
tohttps
, but this is not ideal for my use case, which requires providing an auth token in the URL.Hypothesis:
Network connection lost.
error is returned.Please provide any relevant error logs
No response
The text was updated successfully, but these errors were encountered: