Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issue with Cloudflare Worker #569

Closed
lpellegr opened this issue Mar 30, 2024 · 4 comments
Closed

Compatibility issue with Cloudflare Worker #569

lpellegr opened this issue Mar 30, 2024 · 4 comments

Comments

@lpellegr
Copy link

Using ky 1.2.3 as follows in a Cloudflare Worker instance:

try {
    const response = await ky.post('https://api.ipregistry.co/?key=tryout', {
        json: ["AS1", "AS6", "AS42"],
        headers: {
            "Content-Type": "application/json"
        }
    }).json();

    console.log(response);
} catch (error) {
    console.error(error);
}

produces the following ouput and errors upon execution in a Cloudflare Worker runtime:

✘ [ERROR] Your worker created multiple branches of a single stream (for instance, by calling response.clone() or request.clone()) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the request or response headers and metadata (e.g. in order to be able to modify them), use the appropriate constructors instead (for instance, new Response(response.body, response), new Request(request), etc).

{
results: [
{
allocated: '2001-09-20T00:00:00.000+00:00',
asn: 1,
country_code: 'US',
domain: 'level3.com',
name: 'Level 3 Parent, LLC',
prefixes: [Object],
relationships: [Object],
registry: 'ARIN',
type: 'business',
updated: '2024-02-28T00:00:00.000+00:00'
},
{
allocated: '1984-02-02T00:00:00.000+00:00',
asn: 6,
country_code: 'US',
domain: 'atos.net',
name: 'Atos IT Solutions And Services, Inc.',
prefixes: [Object],
relationships: [Object],
registry: 'ARIN',
type: 'business',
updated: '2021-01-21T00:00:00.000+00:00'
},
{
allocated: '2001-05-16T00:00:00.000+00:00',
asn: 42,
country_code: 'US',
domain: 'pch.net',
name: 'Woodynet, Inc.',
prefixes: [Object],
relationships: [Object],
registry: 'ARIN',
type: 'business',
updated: '2012-03-02T00:00:00.000+00:00'
}
]
}
✘ [ERROR] Your worker created multiple branches of a single stream (for instance, by calling response.clone() or request.clone()) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the request or response headers and metadata (e.g. in order to be able to modify them), use the appropriate constructors instead (for instance, new Response(response.body, response), new Request(request), etc).

✘ [ERROR] Your worker created multiple branches of a single stream (for instance, by calling response.clone() or request.clone()) but did not read the body of both branches. This is wasteful, as it forces the system to buffer the entire stream of data in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the request or response headers and metadata (e.g. in order to be able to modify them), use the appropriate constructors instead (for instance, new Response(response.body, response), new Request(request), etc).

I have no idea about how to work around this. Any idea?

@riderx
Copy link
Contributor

riderx commented May 2, 2024

did you added this in wrangler config
compatibility_flags = ["nodejs_compat"]

@lpellegr
Copy link
Author

lpellegr commented May 2, 2024

Yes, it was.

@blitss
Copy link

blitss commented Jun 7, 2024

Any update here?

@sholladay
Copy link
Collaborator

sholladay commented Aug 12, 2024

We got rid of .clone() for the initial request in Ky 1.4.0, which may help some: #601

However, we still clone the request in case we need to do a retry. I don't think there's any other way to do it, as we can't clone the request after the body has been read, so we need to do it ahead of time in case we need it. Please let me know if anyone comes up with a better way, though.

I'm closing this for now, as I don't think it's actionable.

@sholladay sholladay closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants