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

Fix #123 - request paused on exit #124

Merged
merged 5 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# graphql-upload changelog

## Next

### Patch

- Fixed hanging when a request with a large payload has an “immediate” error, such as a malformed request, fixing [#123](https://github.com/jaydenseric/graphql-upload/issues/123) via [#124](https://github.com/jaydenseric/graphql-upload/pull/124).

## 8.0.1

### Patch
Expand Down
9 changes: 8 additions & 1 deletion src/processRequest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ export const processRequest = (
if (!upload.file) upload.reject(exitError)

request.unpipe(parser)
request.resume()

// With a sufficiently large request body, subsequent events in the same
// event frame cause the stream to pause after the parser is destroyed. To
// ensure that the request resumes, the call to .resume() is scheduled for
// later in the event loop.
setImmediate(() => {
request.resume()
})
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ t.test('Invalid ‘operations’ JSON.', async t => {

body.append('operations', '{ variables: { "file": null } }')
body.append('map', JSON.stringify({ 1: ['variables.file'] }))
body.append('1', 'a', { filename: 'a.txt' })

// We need at least one of these “immediate” failures to have a request body
// larger than node’s internal stream buffer, so that we can test stream
// resumption.
// See: https://github.com/jaydenseric/graphql-upload/issues/123
body.append('1', 'a'.repeat(70000), { filename: 'a.txt' })

const { status } = await fetch(`http://localhost:${port}`, {
method: 'POST',
Expand Down