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](https://private-user-images.githubusercontent.com/28981975/255756657-dc4f435d-5e26-4768-ad08-42424724fd94.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTUzOTI0NzUsIm5iZiI6MTcxNTM5MjE3NSwicGF0aCI6Ii8yODk4MTk3NS8yNTU3NTY2NTctZGM0ZjQzNWQtNWUyNi00NzY4LWFkMDgtNDI0MjQ3MjRmZDk0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTExVDAxNDkzNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk5ZjY4NDk3NGMwNDRmNjZhYzY2ODVhYTgyMDY3NmE3OTY0ZDVkYjlmYTIxYjc2MTllYTU0YTVhODY0MTM2ZGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.AJk_mhCBIPAZFuW6SugloKd4klP4zjEMrDU0Rkb3z9A)
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: