box-node-sdk
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
- [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
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
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.
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
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
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
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
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);
});
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
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
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.
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.