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

TypeError: Found invalid object in transferList #527

Closed
cwkang1998 opened this issue Mar 1, 2023 · 5 comments · Fixed by #543
Closed

TypeError: Found invalid object in transferList #527

cwkang1998 opened this issue Mar 1, 2023 · 5 comments · Fixed by #543
Labels
bug Something isn't working

Comments

@cwkang1998
Copy link

When attempting to run tests using minflare, for some reason I got TypeError: Found invalid object in transferList whilst attempting to clone a response. Not sure why that happens, and suspect that might be a bug, Can someone point me to the correct direction on this?

@mrbbot
Copy link
Contributor

mrbbot commented Mar 1, 2023

Hey! 👋 Could you post the full stack trace for the error? Are you using any byte streams in your Worker? This is possibly related to nodejs/node#45955, which may be fixed by upgrading to Node 19.7.0.

@cwkang1998
Copy link
Author

I'm not using any bytes streams explicitly, but I am using cache.default.

Here's the stacktrace:

     TypeError: Found invalid object in transferList
      at structuredClone (/project/node_modules/undici/lib/fetch/constants.js:109:19)
      at cloneBody (/project/node_modules/undici/lib/fetch/body.js:273:21)
      at cloneResponse (/project/node_modules/undici/lib/fetch/response.js:318:24)
      at Response.clone (/project/node_modules/undici/lib/fetch/response.js:258:28)
      at Response.clone (/project/node_modules/@miniflare/core/src/standards/http.ts:647:38)
      at equal (test/handle.test.ts:242:35)
      at Context.<anonymous> (test/handle.test.ts:217:15)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

@cwkang1998
Copy link
Author

cwkang1998 commented Mar 1, 2023

Currently running on node16, running on node19 produces the same result for me.

The code I'm trying to run:

const actualText = await actual.clone().text()
const expectedText = await expected.clone().text()

Which will result in the aforementioned error

If I manually clone (or recreate?), it seems to work.

const actualResponseClone = new Response(undefined, actual)
const expectedResponseClone = new Response(undefined, expected)

@albertinad
Copy link

albertinad commented Mar 7, 2023

Hi! the same happens to me when running tests that involves cloning the response using Response.clone().

 TypeError: Found invalid object in transferList

    > 68 |   event.waitUntil(cache.put(cacheKey, response.clone()));
         |                                                ^
      69 |
      70 |   return new Response();
      71 | };

      at structuredClone (node_modules/undici/lib/fetch/constants.js:109:19)
      at cloneBody (node_modules/undici/lib/fetch/body.js:273:21)
      at cloneResponse (node_modules/undici/lib/fetch/response.js:318:24)
      at Response.clone (node_modules/undici/lib/fetch/response.js:258:28)
      at Response.clone (node_modules/@miniflare/core/src/standards/http.ts:647:38)

Current setup:

  • jest@^29.4.1
  • jest-environment-miniflare@^2.12.1
  • miniflare@^2.12.1
  • typescript@^4.8.4
  • node v16.14.2

@jdavis
Copy link

jdavis commented Mar 10, 2023

I'm getting this issue as well with code very similar to what @albertinad has. I did confirm though that upgrading to Node 19.7.0 solved the issue that @mrbbot linked to

@mrbbot mrbbot added the bug Something isn't working label Mar 21, 2023
mrbbot added a commit that referenced this issue Mar 22, 2023
This applies the same fix for `Request` bodies from #510 to
`Response`s. Notably, byte streams are returned from lots of Workers
runtime APIs (e.g. KV, R2) to support BYOB reads. It's likely these
are then used in `Response`s and cloned for caching.
mrbbot added a commit that referenced this issue Mar 22, 2023
This applies the same fix for `Request` bodies from #510 to
`Response`s. Notably, byte streams are returned from lots of Workers
runtime APIs (e.g. KV, R2) to support BYOB reads. It's likely these
are then used in `Response`s and cloned for caching.
mrbbot added a commit that referenced this issue Mar 23, 2023
…#543)

This applies the same fix for `Request` bodies from #510 to
`Response`s. Notably, byte streams are returned from lots of Workers
runtime APIs (e.g. KV, R2) to support BYOB reads. It's likely these
are then used in `Response`s and cloned for caching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants