question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid emitting error if upload was not done on closing request

See original GitHub issue

I noticed that when a request ends, if at least one of the uploaded file streams was not consumed, an error is emitted. I’ve found out the hard way, that if you don’t subscribe to the 'error' event on the readable stream, the emission halts the node process and brings down the entire server.

FileStreamDisconnectUploadError: Request disconnected during file upload stream parsing.
    at IncomingMessage.request.on (/dev/project/node_modules/apollo-upload-server/lib/middleware.js:151:15)
    at IncomingMessage.emit (events.js:182:13)
    at resOnFinish (_http_server.js:564:7)
    at ServerResponse.emit (events.js:187:15)
    at onFinish (_http_outgoing.js:683:10)
    at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
    at IncomingMessage.request.on (/dev/project/node_modules/apollo-upload-server/lib/middleware.js:149:32)
    at IncomingMessage.emit (events.js:182:13)
    [... lines matching original stack trace ...]
    at process._tickCallback (internal/process/next_tick.js:61:11)

This has the nasty side-effect of potentially allowing any GraphQL client to send a file under an unexpected field and tear down your server. I realize this after tracing a bug to the UI where the file: Upload field in the mutation was inadvertently being sent as attachment. The API server was dying, without any chance of recovering or catching the error.

You can try this using the apollo-upload-examples. Just change the expected file field in the singleUpload mutation to any other name on the UI and run the upload.

Is there any way of preventing this kind of behavior?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:27 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
twelve17commented, Oct 17, 2019

@mike-marcacci I was handling errors on the graphql upload stream, but failed to do so on the other stream which was sending the data to the backend! So, thanks again for your help in steering me in the right direction. I owe you a 🍺!

1reaction
jaydensericcommented, Jun 18, 2018

Again, the issue is not the current API, it’s that the API does not do what is is supposed to do under the hood. Yes, the right parser error events need to be listened, caught, and then thrown out of the middleware: https://github.com/jaydenseric/apollo-upload-server/issues/77. I just don’t have days and weeks up my sleeve right now to work on it, I am spread super very thin right now.

@mike-marcacci we could split out the tests in #81, which make up about 2/3rds of the diff, into a fast-tracked PR. The tests could be merged a lot quicker and might be helpful if others take a crack at solutions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML input file selection event not firing upon selecting the ...
All I want is to simulate the old school behaviour desktop applications have. If I 'open' the same file again in an desktop...
Read more >
How to use Bloc with streams and concurrency
Bloc 7.2.0 and 8.0.0 introduce a new way to register event handlers. This article provides examples showing the old bloc syntax and how...
Read more >
Frequently Asked Questions - FDA
What Do I Do If My Submission Fails Immediately After Upload? What Do I Do If I Get “The User Services Application was...
Read more >
Angular Debugging "Expression has changed": Explanation ...
This type of error usually shows up beyond the initial development stages, ... Because the page Observable does not initially emit a value, ......
Read more >
How To Work with Files Using Streams in Node.js - DigitalOcean
This event is emitted when you call rl.close() . After writing data to a stream, you have to call the end function on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found