jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Forwarding upload to another service times out (ECONNRESET) #259

Closed sevetseh28 closed 3 years ago

sevetseh28 commented 3 years ago

Hi! I have a webserver acting as a gateway using NestJS and I successfully implemented a Mutation accepting a file with this package (graphql-upload).

The problem I'm currently having is that after accepting the file upload I wanna reupload that file to another service by doing the following HTTP call:

async uploadImage(
    userId: string,
    uploadData: ImageUploadArg,
  ): Promise<{ id: string }> {
    const imgFileUpload: FileUpload = await uploadData.imageFile;
    let data = new FormData();
    data.append('prefix', uploadData.prefix);
    data.append('category', uploadData.category);
    const readStream = imgFileUpload.createReadStream();
    data.append('image', readStream, imgFileUpload.filename);
    return this.httpService
      .post(
        `${this.configService.get('anotherServiceURL')}/${userId}/images`,
        data,
        {
          headers: {
            ...data.getHeaders()
          },
          maxBodyLength: Infinity,
          maxContentLength: Infinity,
        },
      )
      .toPromise()
      .then((res) => {
        return res.data;
      })
  }

Problem is that when calling the http service, it times out with an ECONNRESET error. I am assuming there's something wrong with the read Stream generated by this package. Any ideas?

Im using

Thank you!

jaydenseric commented 3 years ago

Closing because we only keep issues open here that describe a specific graphql-upload bug, or request a new feature. If anyone would like to assist in debugging this problem or has a suggestion, feel free to comment! Also, if you figure it out you're welcome to comment what worked in case it helps others in a similar situation.

sevetseh28 commented 3 years ago

But isnt it possible that this is an actual bug with graphql-upload? Why did you rule it out immediately? Knowing that might help me to debug it. Thanks!

(for instance: https://github.com/jaydenseric/graphql-upload/issues/170)

jaydenseric commented 3 years ago

The way open source works is you debug your own project, and find out if it's a graphql-upload bug. When you are sure it is, then you report it here. What doesn't work, is expecting me to debug your project code (which I don't have easy access to, or a full understanding of) to find out if it's a graphql-upload bug, and pay me nothing when it's not.

The last graphql-upload bug was found in 2019, and since then the package has been installed > 83 million times. People still raise issues asking for help with their projects though. Sometimes a graphql-upload user is stuck on something easy for me to spot and help with and so I do, sometimes not. Either way, the issue is with the project not graphql-upload so it gets closed.

sevetseh28 commented 3 years ago

The way open source works is you debug your own project, and find out if it's a graphql-upload bug. When you are sure it is, then you report it here. What doesn't work, is expecting me to debug your project code (which I don't have easy access to, or a full understanding of) to find out if it's a graphql-upload bug, and pay me nothing when it's not.

The last graphql-upload bug was found in 2019, and since then the package has been installed > 83 million times. People still raise issues asking for help with their projects though. Sometimes a graphql-upload user is stuck on something easy for me to spot and help with and so I do, sometimes not. Either way, the issue is with the project not graphql-upload so it gets closed.

I'm sorry Jayden but I think your attitude is not right at all and you are overreacting. I'm sorry if I didn't debug it enough but the way open source works is helping out the community and don't expect getting paid by doing so. I never expected you or anyone to debug it for me either.

It's sad to see such a reaction and response. Anyhow, thank you.

ivoilic commented 2 years ago

@sevetseh28 Did you ever resolve this? I'm having the same issue. I've tried many variation but it always seems to come back to something being off with the stream itself.

jaydenseric commented 2 years ago

@ivoilic make sure that your sever (i.e. Apache or NGINX) config has limits greater than those configured for graphql-upload, and make sure that you are promisifying and awaiting the end of the file upload streams in resolvers.

jaydenseric commented 17 hours ago

Edit: Sorry, replied in the wrong issue!