BadRequestError: Request disconnected during file upload stream parsing.
See original GitHub issueHi,
When upload my file, I get this error 3/5.
error: uncaughtException: Request disconnected during file upload stream parsing.
BadRequestError: Request disconnected during file upload stream parsing.
at IncomingMessage.abort (/home/wac/development/test/world-of-hytale/server/node_modules/apollo-server-core/node_modules/graphql-upload/lib/processRequest.js:115:9)
at Object.onceWrapper (events.js:427:28)
at IncomingMessage.emit (events.js:321:20)
at resOnFinish (_http_server.js:685:7)
at ServerResponse.emit (events.js:333:22)
at onFinish (_http_outgoing.js:730:10)
at onCorkedFinish (_stream_writable.js:721:5)
at afterWrite (_stream_writable.js:528:5)
at afterWriteTick (_stream_writable.js:515:10)
at processTicksAndRejections (internal/process/task_queues.js:83:21) {"error":{"message":"Request disconnected during file upload stream parsing.","expose":true,"statusCode":499,"status":499},"stack":"BadRequestError: Request disconnected during file upload stream parsing.\n at IncomingMessage.abort (/home/wac/development/test/world-of-hytale/server/node_modules/apollo-server-core/node_modules/graphql-upload/lib/processRequest.js:115:9)\n at Object.onceWrapper (events.js:427:28)\n at IncomingMessage.emit (events.js:321:20)\n at resOnFinish (_http_server.js:685:7)\n at ServerResponse.emit (events.js:333:22)\n at onFinish (_http_outgoing.js:730:10)\n at onCorkedFinish (_stream_writable.js:721:5)\n at afterWrite (_stream_writable.js:528:5)\n at afterWriteTick (_stream_writable.js:515:10)\n at processTicksAndRejections (internal/process/task_queues.js:83:21)","exception":true,"date":"Tue Mar 03 2020 23:14:41 GMT+0100 (Central European Standard Time)","process":{"pid":12579,"uid":1000,"gid":1000,"cwd":"/home/wac/development/test/world-of-hytale/server","execPath":"/usr/local/bin/node","version":"v12.16.0","argv":["/usr/local/bin/node","/home/wac/development/test/world-of-hytale/server/src/app.ts"],"memoryUsage":{"rss":261173248,"heapTotal":196616192,"heapUsed":169225944,"external":2689616}},"os":{"loadavg":[2.76318359375,2.45166015625,2.21484375],"uptime":13204},"trace":[{"column":9,"file":"/home/wac/development/test/world-of-hytale/server/node_modules/apollo-server-core/node_modules/graphql-upload/lib/processRequest.js","function":"IncomingMessage.abort","line":115,"method":"abort","native":false},{"column":28,"file":"events.js","function":"Object.onceWrapper","line":427,"method":"onceWrapper","native":false},{"column":20,"file":"events.js","function":"IncomingMessage.emit","line":321,"method":"emit","native":false},{"column":7,"file":"_http_server.js","function":"resOnFinish","line":685,"method":null,"native":false},{"column":22,"file":"events.js","function":"ServerResponse.emit","line":333,"method":"emit","native":false},{"column":10,"file":"_http_outgoing.js","function":"onFinish","line":730,"method":null,"native":false},{"column":5,"file":"_stream_writable.js","function":"onCorkedFinish","line":721,"method":null,"native":false},{"column":5,"file":"_stream_writable.js","function":"afterWrite","line":528,"method":null,"native":false},{"column":10,"file":"_stream_writable.js","function":"afterWriteTick","line":515,"method":null,"native":false},{"column":21,"file":"internal/process/task_queues.js","function":"processTicksAndRejections","line":83,"method":null,"native":false}]}
[nodemon] app crashed - waiting for file changes before starting...
I am however waiting for my promise like that.
/**
*
* @param filename
* @param createReadStream
*/
export const writeStream = (
filename: string,
createReadStream: () => Stream,
): Promise<any> => {
return new Promise(async (resolve, reject) => {
const stream = await createReadStream()
.pipe(createWriteStream(`${env.upload.uploadDir}/${filename}`))
.on('finish', () => resolve(stream))
.on('error', reject)
});
}
const file = await writeStream(filename, createReadStream);
Am I missing something? I use apollo-server-express 😕
Thanks 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Request disconnected during file upload stream parsing ...
If I attach on('error) to stream it gets an error: (node:13672) UnhandledPromiseRejectionWarning: BadRequestError: Request disconnected during ...
Read more >Apollo Server: Request disconnected during file upload ...
The error only occurs when I try to send it in a request. If I replace the stream with fs.createReadStream("filePath") the request works...
Read more >How to troubleshoot GraphQL file upload issue with Nest.js ...
... Run with GraphQL file upload(Apollo Server), got this error: BadRequestError: Request disconnected during file upload stream parsing. at ...
Read more >graphql-upload
The device requires sufficient disk space to buffer the expected number of concurrent upload requests. Promisify and await file upload streams ...
Read more >GraphQL File Uploads to Various Node.js GraphQL Server
Promisify and await file upload streams in resolvers or the server will send a response to the client before uploads are complete, causing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@KiziKr also note that node’s streams don’t automatically propagate errors (although this may change in node 14).
In your example, you are attaching an
error
handler to the destination stream (which is the return value ofreadable.pipe(writable)
) but aren’t adding one to the the source stream.Based on your error message I am almost certain that something else (like a load balancer, proxy, etc) is aborting the request mid-way through. The error that’s being emitted is not being handled, and so your node process crashes.
Modifying your handler to propagate errors should resolve the crash:
However, the actual error comes from the request being closed before it is finished, and originates either in the client or any intermediate proxies or network devices.
Thanks for the info.
It seems you are aware that there needs to be only 1
graphql-upload
version installed innode_modules
, preferably the latest. I can’t guarantee Apollo server will work with the manually updated version, but it probably should be ok.One idea is to consider is the size limits for request size, etc. for you server (nginx, etc.) as it can disconnect when exceeded. The right way to enforce limits is to set the upload middleware options to be within your server limits; that way you will get more elegant error messages when they are exceeded. I’m not sure from memory how to set those upload options via Apollo server, but there should be documentation somewhere.