ladjs / supertest

🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: write EPIPE on large files - Next.js + Jest + Supertest

dasveloper opened this issue · comments

Describe the bug

Node.js version: v18.14.2

OS version: macOS 13.4

Description: With Next.js + Jest + Supertest, when attaching a 10mb file to my post request I'm getting the error "write EPIPE"

Actual behavior

Test fails with the error "write EPIPE"

Screenshot 2023-07-24 at 8 42 24 PM

Expected behavior

Test should succeed with no error

Code to reproduce

https://github.com/dasveloper/next-test-supertest

    await testClient(endpointHandler)
      .post("/endpoint")
      .field("name", "John Doe")
      .attach("avatar", Buffer.from("a".repeat(10000000)), "filename")
      .expect({ success: true })
      .expect(200);

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

We have a pretty vanilla express.js app (a REST API) that uses supertest with mocha for testing. We recently upgraded it from Node.js 14.15.5 to the latest Node.js 18.x release (18.18.2) and all of a sudden the tests which upload files via the attach function started failing with this error:

Error: write EPIPE
      at afterWriteDispatched (node:internal/stream_base_commons:160:15)
      at writeGeneric (node:internal/stream_base_commons:151:3)
      at Socket._writeGeneric (node:net:962:11)
      at Socket._write (node:net:974:8)
      at doWrite (node:internal/streams/writable:411:12)
      at clearBuffer (node:internal/streams/writable:572:7)
      at Writable.uncork (node:internal/streams/writable:351:7)
      at connectionCorkNT (node:_http_outgoing:951:8)
      at process.processTicksAndRejections (node:internal/process/task_queues:81:21)

After much Googling I stumbled on this issue. The files we're uploading in our tests were images 100K in size, so I tried replacing them with a 1x1 pixel JPEG that is only 3K in size, but the error still occurred, so despite what the OP suggests, I'm not convinced this has anything to do with file size of the attachment.

The only thing that we changed was the Node.js version, and we kept all other dependency versions the same, so clearly something in Node.js was breaking this. Given that, I started downgrading Node.js from 18.18.2 to find where it starts breaking, and it starts breaking in Node.js 18.13.0

Here are the release notes for Node.js 18.13.0:

https://nodejs.org/en/blog/release/v18.13.0