box-node-sdk icon indicating copy to clipboard operation
box-node-sdk copied to clipboard

Migrate to Axios because files.uploadFile() not working with error ESOCKETTIMEDOUT after upgrading the nodejs version to 16.4 LTS with request lib

Open SharikSaigal87 opened this issue 2 years ago • 9 comments

  • [X] I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
  • [X] I have checked that the [API documentation][api-docs] doesn't solve my issue.
  • [X] I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
  • [X ] I have searched [Issues in this repo][github-repo] and my issue isn't already reported.

Description of the Issue

files.uploadFile() not working with node version 16.4 same was working fine with node version 14 Observed related issues https://github.com/box/boxcli/issues/238 https://github.com/box/boxcli/issues/231

Steps to Reproduce

Use box-node-sdk uploadFIle to upload in a system where node version is 16.4

Expected Behavior

the file should be uploaded successfully and box upload should also be supported in node version 16.4

Error Message, Including Stack Trace

Caused by: Error: ESOCKETTIMEDOUT at ClientRequest. (/projects/projects_crt/tools/box_cli2/node_modules/@box/cli/node_modules/request/request.js:816:19) at Object.onceWrapper (node:events:482:28) at ClientRequest.emit (node:events:376:20)

Screenshots

Versions Used

NodeJS: 16.4 box-node-sdk: 2.0.0

SharikSaigal87 avatar Mar 30 '22 08:03 SharikSaigal87

Hi @SharikSaigal87

Thank you for reporting the issue! This issue was recently posted in our CLI repo box/boxcli#298, and we will try to address this soon.

Did you encounter this problem in the node sdk or in the CLI? I see a reference to the CLI in your stacktrace.

Thanks, Mateusz

mwwoda avatar Mar 30 '22 14:03 mwwoda

Hi @mwwoda , Thank you for looking into it and hope this is fixed soon . I have encountered this issue with box node sdk and the error is same ESOCKETTIMEDOUT on line node_modules/request/request.js:816:19 , when performing operations files.uploadFile() or files.uploadNewFileVersion() and other SDK supported operations like chunk upload are working fine on a system with nodejs version 16 installed.

SharikSaigal87 avatar Mar 31 '22 05:03 SharikSaigal87

I've confirmed that the error happens in Node 16 while Node 14 works fine. Based on our research the problem is that box-node-sdk currently uses https://www.npmjs.com/package/request to make requests. We're planning to migrate away from this library. Let's keep this open to monitor the progress on the migration

mhagmajer avatar May 09 '22 13:05 mhagmajer

is there any progress on this ? I had a ESOCKETTIMEDOUT this week on one of our files uploads.

This happened after one minute, and thus not getting back any response, jus the error

But the file was correctly uploaded.

This failure happens occasionally, but it makes the whole process unreliable

thanks

huineng avatar Sep 28 '22 10:09 huineng

Hi @huineng ,

In the current sprint, we check whether the replacement of the request library to axios in terms of uploading the file works. If so, we plan to add axios to the project in the next sprints after proper planning.

Sorry for troubles, Artur

arjankowski avatar Sep 28 '22 12:09 arjankowski

Hi @huineng

As it turned out, in our testing we were unable to reproduce this bug with an ESOCKETTIMEDOUT error on node 16.

Could you please share with us your code which causes the mentioned bug? This may help us with further investigation.

Additionally, can you tell us what operating system you are running your code on and which node version you are using?

Thanks Artur

arjankowski avatar Sep 30 '22 14:09 arjankowski

thanks, but i'm sorry i cannot easily reproduce this error myself , as like i said, it was the first time i encountered this

anyway this was the box response that we log in case of error, not sure if it can help

{
 "code": "ESOCKETTIMEDOUT",
 "connect": false,
 "request": {
   "uri": {
     "protocol": "https:",
     "slashes": true,
     "auth": null,
     "host": "[upload.box.com](http://upload.box.com/)",
     "port": 443,
     "hostname": "[upload.box.com](http://upload.box.com/)",
     "hash": null,
     "search": null,
     "query": null,
     "pathname": "/api/2.0/files/content",
     "path": "/api/2.0/files/content",
     "href": "https://upload.box.com/api/2.0/files/content"
   },
   "method": "POST",
   "headers": {
     "User-Agent": "Box Node.js SDK v2.5.0 (Node v16.14.0)",
     "Authorization": "[REMOVED BY SDK]",
     "X-Box-UA": "agent=box-node-sdk/2.5.0; env=Node/16.14.0",
     "host": "[upload.box.com](http://upload.box.com/)",
     "accept": "application/json",
     "content-type": "multipart/form-data; boundary=--------------------------937445028149437501030745",
     "content-length": 1003383
   }
 }
}

the item i found closes to the request library issue was this https://github.com/request/request/issues/2676#issuecomment-470703073

this runs in a docker container ubi9/nodejs-16 so rhel 9 node 16 I hope this helps a bit

my code to upload looks a bit like this

const boxResponse = await box.files
        .uploadFile(folderId, file.name, file.data, {
            description,
        } as any)
        .catch(async (error: IBoxError) => {
            // box always returns a response.body
            const response: { [index: string]: any } = error.response?.body || { ...error };

            if (response.status === 409) {
                return Promise.resolve(response.code);
            }

            const err: {  response: string; folderId: string; message: string; code: string } = {
                folderId,
                response: JSON.stringify(response, null, 2),
                message: error.message || 'Box Error',
                code: error.code,
            };

            return Promise.reject(err);
        });

huineng avatar Sep 30 '22 14:09 huineng

Hi @huineng thanks for your code but unfortunately I still haven't been able to reproduce this problem.

But for the next quarter we have already planned at least a change of the upload part in our SDK using a different library than request. Hopefully this will fix this upload problem, so our Node SDK can be easily used with Node 16.

Regards, Artur

arjankowski avatar Oct 03 '22 14:10 arjankowski

thanks, i know it's difficult to debug , i only had it once after hundreds of uploads. And i will watch any new releases. As request module is deprecated, i think it's a good move

Thanks for your support

huineng avatar Oct 03 '22 14:10 huineng

This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

stale[bot] avatar Dec 19 '22 19:12 stale[bot]

This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box Node SDK and feel free to open another PR/issue at any time.

stale[bot] avatar Dec 26 '22 20:12 stale[bot]