-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Apollo must wait to respond until request completes #2843
Comments
I can also confirm this issue on apollo-server-koa. I can also confirm that applying the changes from https://github.com/jaydenseric/graphql-upload/blob/837bbdfb617c740bc19fb34ee6bf1c9553f688c9/src/graphqlUploadKoa.mjs#L29..L40 to @mike-marcacci Nevertheless, I do not think that the server should process the whole request if he already determined that the user should not upload (e.g. rate limitings or amount of allowed files is exceeded). Is this a known limitation of |
@n1mmy this is not really a limitation of The only correct way to handle this is to delay closing the connection until the entire request has been received. Now, when testing this with especially small payloads, you may not see this behavior since node (or the server OS) can buffer the remainder of the request such that entire payload has been sent even though it hasn't been received. This is what makes this issue so insidious: it often doesn't appear in tests, where we use small mock files, then rears its head nondeterministically in production. You may note that in |
I wonder if this is the issue in having. I thought it was depending on file size, but maybe its not |
I maybe also have fixed my apollo-server-graphql by adding:
Above processFileUploads in ApolloServer.js |
Patch for [email protected]: diff --git a/node_modules/apollo-server-koa/dist/ApolloServer.js b/node_modules/apollo-server-koa/dist/ApolloServer.js
index 51a1e42..4ced9a4 100644
--- a/node_modules/apollo-server-koa/dist/ApolloServer.js
+++ b/node_modules/apollo-server-koa/dist/ApolloServer.js
@@ -35,6 +35,7 @@ var apollo_server_core_2 = require("apollo-server-core");
exports.GraphQLExtension = apollo_server_core_2.GraphQLExtension;
const fileUploadMiddleware = (uploadsConfig, server) => (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
if (type_is_1.default(ctx.req, ['multipart/form-data'])) {
+ const finished = new Promise(resolve => ctx.req.on('end', resolve))
try {
ctx.request.body = yield apollo_server_core_1.processFileUploads(ctx.req, ctx.res, uploadsConfig);
return next();
@@ -46,6 +47,8 @@ const fileUploadMiddleware = (uploadsConfig, server) => (ctx, next) => __awaiter
formatter: server.requestOptions.formatError,
debug: server.requestOptions.debug,
});
+ } finally {
+ yield finished
}
}
else { |
Same issue here, when I try to upload upload multiple files I randomly get an "Network Error: Failed to fetch" error... |
@OwenCalvin we finally decided to upload to AWS S3 directly. It reduces the server load and we now simply generate pre-signed URLs. |
Hello, noticed there are no updates for almost a year - is this is hard to use compatibility with graphql-upload/koa or graphql-upload/express? Want to up this issue, it's pretty critical one. |
Apollo Server 3 no longer has a built-in integration with graphql-upload. If the issues still applies (eg, if manual integration with graphql-upload suffers from the same problem in a way that requires changes to Apollo Server to fix), let me know and we can reopen! |
It appears that all the
apollo-server-
packages suffer from a bug when usinggraphql-upload
. It is essential to wait for an entire HTTP request to be consumed before responding, or you risk causing very hard-to-diagnose bugs, including locking a browser out of subsequent requests to the server.The middleware that comes with
graphql-upload
does this, but was being bypassed ingraphql-upload-express
, which I fixed here. However, I noticed that the upload middleware bundled with Apollo fails to wait, and will experience these bugs even with that fix.Please see this issue for context and details (specifically this comment) the accompanying demonstration repo put together with heroic effort by @juona.
This middleware in apollo-server-express might be able to borrow from this one in graphql-upload/express.
This middleware in apollo-server-koa might take from this in graphql-upload/koa.
The text was updated successfully, but these errors were encountered: