I'm receiving "Error [TimeoutError]: Connection timed out after 120000ms" error in the below part of the nestJS code when I trying to get the request that return my service.
node:events:368 throw er; // Unhandled 'error' event ^
Error [TimeoutError]: Connection timed out after 120000ms at ClientRequest. (C:\Users\citDe\Documents\Api\node_modules\aws-sdk\lib\http\node.js:86:34) at Object.onceWrapper (node:events:509:28) at ClientRequest.emit (node:events:390:28) at ClientRequest.emit (node:domain:475:12) at TLSSocket.emitRequestTimeout (node:_http_client:763:9) at Object.onceWrapper (node:events:509:28) at TLSSocket.emit (node:events:402:35) at TLSSocket.emit (node:domain:475:12) at TLSSocket.Socket._onTimeout (node:net:501:8) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) Emitted 'error' event on PassThrough instance at: at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'TimeoutError',
time: 2023-09-26T15:52:56.983Z, region: 'us-east-1', hostname: 'name.s3.amazonaws.com', retryable: false, statusCode: 200,
retryDelay: 92.74054227815466 }
The service, which is a GET Request, aims to create a temporary link for downloading a ZIP file. In summary, what it does is retrieve PDF files from S3, compress them with the help of the "archiver" library, and then upload the ZIP file to an S3 bucket. If the ZIP file already exists, it skips the previous steps and only fetches it from the bucket to generate the temporary link.
The problem is that I receive the error "Error [TimeoutError]: Connection timed out after 120000ms" when I execute the GET request. I know that the error occurs because the request didn't resolve within the estimated time. However, it seems that there's more to it. There's a whole line of possible solutions discussed in a GitHub question, but most of them point to the issue possibly being related to not properly closing the stream, and as a result, the promise isn't resolving.
Additionally, the downloaded files are not very large in size. Increasing the timeout in the SDK configuration wouldn't be the exact solution. So, my question is, how can I manually close the stream once the response has been successful?
I've attached the StackBlitz where I've left the code I'm using. I'm using Node.js since it's compatible with my current environment.
I would appreciate any kind of help. Thank you in advance. Regards.