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

client.files.getReadStream gets stuck when data is not immediately read

Open bskiff opened this issue 2 years ago • 1 comments

  • [x] I have checked that the SDK documentation doesn't solve my issue.
  • [x] I have checked that the API documentation doesn't solve my issue.
  • [x] I have searched the Box Developer 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 and my issue isn't already reported.

Description of the Issue

When data is not read synchronously from the read stream returned from client.files.getReadStream, the data is never provided and the stream is not closed.

The issue was already reported in #704, but was not resolved. It is still an issue, and hopefully our examples/workarounds can provide some additional insight.

Steps to Reproduce

const sdkInstance = BoxSDK.getPreconfiguredInstance(config);
const client = sdkInstance.getAppAuthClient('enterprise');

const fileStream = await client.files.getReadStream(fileId);

setTimeout(() => {
  // data never loads!
  fileStream.pipe(process.stdout);
}, 1000);

We were able to workaround this issue by adding in a Passthrough that doesn't do anything.

const sdkInstance = BoxSDK.getPreconfiguredInstance(config);
const client = sdkInstance.getAppAuthClient('enterprise');

const fileStream = await client.files.getReadStream(fileId);

const passThrough = new PassThrough();
fileStream.pipe(passThrough);

setTimeout(() => {
  // data loads!
  passThrough.pipe(process.stdout);
}, 1000);

Expected Behavior

Data is never made available on the stream, if the first read from the stream occurs asynchronously.

Error Message, Including Stack Trace

Screenshots

Versions Used

Node SDK: 2.5.0, 2.6.0

bskiff avatar Sep 26 '22 18:09 bskiff

Hi @bskiff,

Thanks for your insights! I've created a jira ticket for my team (jira-2645), so we can look into this soon.

@arjankowski

arjankowski avatar Sep 27 '22 08:09 arjankowski

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]

Hi @bskiff,

We have just fixed this issue using PassThrough, and it will be available in the next Box Node SDK release.

Thank you for your solution, and if you have any other problem, feel free to let us know.

Regards, Minh

congminh1254 avatar Jan 03 '23 16:01 congminh1254

Thanks @congminh1254!

bskiff avatar Jan 03 '23 18:01 bskiff

Hi @bskiff ,

We did a release contains your bug fix, you can use Node SDK 2.8.1 to verify if it works for you.

Regards, Minh

congminh1254 avatar Jan 05 '23 12:01 congminh1254

We pulled in the new version, and it's working! Thanks again @congminh1254!

bskiff avatar Jan 06 '23 17:01 bskiff