box / box-typescript-sdk-gen

Repository for generated Box TS SDK
Apache License 2.0
14 stars 2 forks source link

Error on upload using uploadBigFile #222

Open singleonlinehome opened 3 months ago

singleonlinehome commented 3 months ago

Description of the Issue

Trying to use the bigFileUpload chunked uploading process to upload a large file from a stream from S3, the stream doesn't throw any errors but after the upload appears to complete the following error is thrown:

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ClientRequest'
    |     property 'socket' -> object with constructor 'TLSSocket'
    --- property '_httpMessage' closes the circle
    at JSON.stringify (<anonymous>)
    at new BoxSdkError (/Users/david/repos/ixxxnode_modules/box-typescript-sdk-gen/lib/box/errors.js:9:29)
    at new BoxApiError (/Users/david/repos/xxx/node_modules/box-typescript-sdk-gen/lib/box/errors.js:15:9)
    at /Users/david/repos/xxx/node_modules/box-typescript-sdk-gen/lib/networking/fetch.js:154:19
    at Generator.next (<anonymous>)
    at fulfilled (/Users/david/repos/xxx/node_modules/box-typescript-sdk-gen/lib/networking/fetch.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected Behavior

Upload to complete successfully or error raised correctly

Versions Used

Typescript SDK: 1.0.0 Platform: Node.js 20.14

mwwoda commented 3 months ago

Hi @singleonlinehome

Thank you for reporting the problem. Could you please provide a minimal, reproducible sample code (preferably a project that we could download and run) that we could use to reproduce the problem? Does this only happen when interacting with streams from s3? Is the file still uploaded to Box despite the error?

singleonlinehome commented 3 months ago

@mwwoda I'll try and get something working that doesn't expose internal IP.

The file is not uploaded.

I have got more detailed errors by commenting the following line from the error.js output which is where the cirular error comes.

    this.message = JSON.stringify(fields, undefined, 2);

The underlying error is to do with mismatched part sizes:

BoxApiError: 400
    at /Users/david/repos/xxx/node_modules/box-typescript-sdk-gen/lib/networking/fetch.js:154:19
    at Generator.next (<anonymous>)
    at fulfilled (/Users/david/repos/xxx/node_modules/box-typescript-sdk-gen/lib/networking/fetch.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  timestamp: '1718018863351',
  requestInfo: {
    method: 'PUT',
    url: 'https://upload.box.com/api/2.0/files/upload_sessions/54B3996E1D6CD3C8A8B96ECE745677BA',
    queryParams: {},
    headers: {
      'Content-Type': 'application/octet-stream',
      digest: 'sha=GvUZwyRIoXU5NJFtv8EZkwqKOxs=',
      'content-range': 'bytes 536870912-576030758/578688267',
      Authorization: 'Bearer 1!xxx.',
      'User-Agent': 'Box JavaScript generated SDK v1.0.0 (Node v20.14.0)',
      'X-Box-UA': 'agent=box-javascript-generated-sdk/1.0.0; env=Node/20.14.0'
    },
    body: Readable {
      _events: [Object],
      _readableState: [ReadableState],
      _read: [Function: read],
      _maxListeners: undefined,
      _eventsCount: 2,
      [Symbol(shapeMode)]: true,
      [Symbol(kCapture)]: false
    }
  },
  responseInfo: {
    statusCode: 400,
    headers: {
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
      connection: 'close',
      'content-length': '138',
      'content-type': 'application/json;charset=utf-8',
      date: 'Mon, 10 Jun 2024 11:27:43 GMT',
      server: 'nginx',
      'strict-transport-security': 'max-age=31536000',
      via: '1.1 google'
    },
    body: {
      code: 'invalid_part_size',
      message: 'Part size 39159847 not equal to expected 67108864',
      request_id: '56adfd5d74ebcb455402269391bea882'
    },
    rawBody: '{"code":"invalid_part_size","message":"Part size 39159847 not equal to expected 67108864","request_id":"56adfd5d74ebcb455402269391bea882"}',
    code: '"invalid_part_size"',
    contextInfo: undefined,
    requestId: '"56adfd5d74ebcb455402269391bea882"',
    helpUrl: undefined
  }
}

Issue does not show when using the legacy Node Box SDK using the exact same S3 download stream.

congminh1254 commented 3 months ago

Hi @singleonlinehome

Thanks for this issue, we may found the root cause and implementing the fix.

I will let you know when the fix is available to use.

Bests, Minh

singleonlinehome commented 3 months ago

@congminh1254 Thanks for the update. Looking forward to getting a fix and being able to migrate from the legacy SDK.

congminh1254 commented 1 month ago

Hi @singleonlinehome Can you try the latest version of the SDK to see if it's working now. Bests, Minh