aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

aws-crypto lib: Cannot read properties of undefined (reading 'byteLength') #9265

Closed hisham closed 10 months ago

hisham commented 2 years ago

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

REST API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: macOS 11.5.2 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Memory: 4.81 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node npm: 7.19.1 - ~/.nvm/versions/node/v14.15.3/bin/npm Watchman: 2021.10.04.00 - /usr/local/bin/watchman Browsers: Chrome: 96.0.4664.55 Edge: 95.0.1020.53 Firefox: 94.0.1 Safari: 14.1.2 npmPackages: @angular-builders/custom-webpack: ^12.1.0 => 12.1.0 @angular-devkit/build-angular: ^12.1.1 => 12.1.1 @angular-eslint/builder: ^12.0.0 => 12.2.0 @angular-eslint/eslint-plugin: ^12.0.0 => 12.2.0 @angular-eslint/eslint-plugin-template: ^12.0.0 => 12.2.0 @angular-eslint/schematics: 12.2.0 => 12.2.0 @angular-eslint/template-parser: ^12.0.0 => 12.2.0 @angular/animations: ~12.1.1 => 12.1.1 (11.0.3) @angular/animations/browser: undefined () @angular/animations/browser/testing: undefined () @angular/cdk: ^12.1.1 => 12.1.1 @angular/cdk/a11y: undefined () @angular/cdk/accordion: undefined () @angular/cdk/bidi: undefined () @angular/cdk/clipboard: undefined () @angular/cdk/coercion: undefined () @angular/cdk/collections: undefined () @angular/cdk/drag-drop: undefined () @angular/cdk/keycodes: undefined () @angular/cdk/layout: undefined () @angular/cdk/observers: undefined () @angular/cdk/overlay: undefined () @angular/cdk/platform: undefined () @angular/cdk/portal: undefined () @angular/cdk/scrolling: undefined () @angular/cdk/stepper: undefined () @angular/cdk/table: undefined () @angular/cdk/testing: undefined () @angular/cdk/testing/protractor: undefined () @angular/cdk/testing/selenium-webdriver: undefined () @angular/cdk/testing/testbed: undefined () @angular/cdk/text-field: undefined () @angular/cdk/tree: undefined () @angular/cli: ~12.1.1 => 12.1.1 @angular/common: ~12.1.1 => 12.1.1 (11.0.3) @angular/common/http: undefined () @angular/common/http/testing: undefined () @angular/common/testing: undefined () @angular/common/upgrade: undefined () @angular/compiler: ~12.1.1 => 12.1.1 @angular/compiler-cli: ^12.1.1 => 12.1.1 @angular/compiler/testing: undefined () @angular/core: ~12.1.1 => 12.1.1 (11.0.3) @angular/core/testing: undefined () @angular/elements: ~12.1.1 => 12.1.1 @angular/forms: ~12.1.1 => 12.1.1 @angular/material: ^12.1.1 => 12.1.1 @angular/material/autocomplete: undefined () @angular/material/autocomplete/testing: undefined () @angular/material/badge: undefined () @angular/material/badge/testing: undefined () @angular/material/bottom-sheet: undefined () @angular/material/bottom-sheet/testing: undefined () @angular/material/button: undefined () @angular/material/button-toggle: undefined () @angular/material/button-toggle/testing: undefined () @angular/material/button/testing: undefined () @angular/material/card: undefined () @angular/material/card/testing: undefined () @angular/material/checkbox: undefined () @angular/material/checkbox/testing: undefined () @angular/material/chips: undefined () @angular/material/chips/testing: undefined () @angular/material/core: undefined () @angular/material/core/testing: undefined () @angular/material/datepicker: undefined () @angular/material/datepicker/testing: undefined () @angular/material/dialog: undefined () @angular/material/dialog/testing: undefined () @angular/material/divider: undefined () @angular/material/divider/testing: undefined () @angular/material/expansion: undefined () @angular/material/expansion/testing: undefined () @angular/material/form-field: undefined () @angular/material/form-field/testing: undefined () @angular/material/form-field/testing/control: undefined () @angular/material/grid-list: undefined () @angular/material/grid-list/testing: undefined () @angular/material/icon: undefined () @angular/material/icon/testing: undefined () @angular/material/input: undefined () @angular/material/input/testing: undefined () @angular/material/list: undefined () @angular/material/list/testing: undefined () @angular/material/menu: undefined () @angular/material/menu/testing: undefined () @angular/material/paginator: undefined () @angular/material/paginator/testing: undefined () @angular/material/progress-bar: undefined () @angular/material/progress-bar/testing: undefined () @angular/material/progress-spinner: undefined () @angular/material/progress-spinner/testing: undefined () @angular/material/radio: undefined () @angular/material/radio/testing: undefined () @angular/material/select: undefined () @angular/material/select/testing: undefined () @angular/material/sidenav: undefined () @angular/material/sidenav/testing: undefined () @angular/material/slide-toggle: undefined () @angular/material/slide-toggle/testing: undefined () @angular/material/slider: undefined () @angular/material/slider/testing: undefined () @angular/material/snack-bar: undefined () @angular/material/snack-bar/testing: undefined () @angular/material/sort: undefined () @angular/material/sort/testing: undefined () @angular/material/stepper: undefined () @angular/material/stepper/testing: undefined () @angular/material/table: undefined () @angular/material/table/testing: undefined () @angular/material/tabs: undefined () @angular/material/tabs/testing: undefined () @angular/material/toolbar: undefined () @angular/material/toolbar/testing: undefined () @angular/material/tooltip: undefined () @angular/material/tooltip/testing: undefined () @angular/material/tree: undefined () @angular/material/tree/testing: undefined () @angular/platform-browser: ~12.1.1 => 12.1.1 (11.0.3) @angular/platform-browser-dynamic: ~12.1.1 => 12.1.1 @angular/platform-browser-dynamic/testing: undefined () @angular/platform-browser/animations: undefined () @angular/platform-browser/testing: undefined () @angular/router: ~12.1.1 => 12.1.1 (11.0.3) @angular/router/testing: undefined () @angular/router/upgrade: undefined () @gammastream/scully-plugin-sitemap: ^1.0.7 => 1.0.7 @ng-select/ng-option-highlight: 0.0.6 => 0.0.6 @ng-select/ng-select: ^7.1.0 => 7.1.0 @ngneat/until-destroy: ^8.0.3 => 8.0.4 @scullyio/init: ^1.1.4 => 1.1.4 @scullyio/ng-lib: ^1.1.1 => 1.1.1 @scullyio/scully: ^1.1.1 => 1.1.1 @scullyio/scully-plugin-critical-css: 0.1.1 => 0.1.1 @sentry/angular: ^6.13.2 => 6.13.2 @sentry/cli: ^1.66.0 => 1.66.0 @sentry/tracing: ^6.13.2 => 6.13.2 (5.30.0) @types/applepayjs: ^3.0.1 => 3.0.1 @types/cheerio: ^0.22.23 => 0.22.29 @types/imagemin: ^7.0.0 => 7.0.0 @types/imagemin-gifsicle: ^7.0.0 => 7.0.0 @types/imagemin-mozjpeg: ^8.0.0 => 8.0.0 @types/imagemin-optipng: ^5.2.0 => 5.2.0 @types/imagemin-svgo: ^8.0.0 => 8.0.1 @types/jasmine: ~3.6.0 => 3.6.11 @types/jasminewd2: ~2.0.3 => 2.0.9 @types/js-beautify: ^1.13.1 => 1.13.1 @types/jsdom: ^16.2.5 => 16.2.12 @types/marked: ^1.2.0 => 1.2.2 @types/node: 14.0.4 => 14.0.4 @types/node-zendesk: ^1.4.0 => 1.4.0 @types/yamljs: ^0.2.31 => 0.2.31 @typescript-eslint/eslint-plugin: 4.23.0 => 4.23.0 @typescript-eslint/parser: 4.23.0 => 4.23.0 (3.10.1) angular-cc-library: ^2.1.2 => 2.1.2 array-flat-polyfill: ^1.0.1 => 1.0.1 aws-amplify: ^4.3.4 => 4.3.4 axios: ^0.21.1 => 0.21.4 body-parser: ^1.19.0 => 1.19.0 cheerio: ^1.0.0-rc.3 => 1.0.0-rc.10 (0.22.0) commander: ^2.20.3 => 2.20.3 (4.1.1, 7.2.0, 2.13.0, 6.2.1) document-register-element: ^1.7.2 => 1.14.10 dotenv-webpack: ^7.0.3 => 7.0.3 eslint: ^7.26.0 => 7.30.0 eslint-config-prettier: ^8.3.0 => 8.3.0 eslint-plugin-import: latest => 2.23.4 eslint-plugin-jsdoc: latest => 35.4.1 eslint-plugin-prefer-arrow: latest => 1.2.3 eslint-plugin-react: latest => 7.24.0 example-typescript: 1.0.0 fast-xml-parser: ^3.17.6 => 3.19.0 folder-hash: ^3.3.0 => 3.3.3 fractional: ^1.0.0 => 1.0.0 front-matter: ^4.0.2 => 4.0.2 fs-extra: ^9.0.0 => 9.1.0 (8.1.0, 1.0.0) image-size: ^0.9.7 => 0.9.7 (0.5.5, 0.6.3) imagemin: ^7.0.1 => 7.0.1 imagemin-gifsicle: ^7.0.0 => 7.0.0 imagemin-mozjpeg: ^9.0.0 => 9.0.0 imagemin-optipng: ^8.0.0 => 8.0.0 imagemin-svgo: ^8.0.0 => 8.0.0 jasmine-core: ~3.6.0 => 3.6.0 (2.8.0) jasmine-spec-reporter: ~5.0.0 => 5.0.2 js-beautify: ^1.13.0 => 1.14.0 js-yaml-loader: ^1.2.2 => 1.2.2 json_encode: ^0.1.0 => 0.1.0 karma: ~6.3.4 => 6.3.4 karma-chrome-launcher: ~3.1.0 => 3.1.0 karma-coverage-istanbul-reporter: ~3.0.2 => 3.0.3 karma-jasmine: ~4.0.0 => 4.0.1 karma-jasmine-html-reporter: ^1.5.0 => 1.6.0 lib: 0.0.1 libphonenumber-js: ^1.8.3 => 1.9.20 libphonenumber-js-core: 1.0.0 libphonenumber-js-max: 1.0.0 libphonenumber-js-min: 1.0.0 libphonenumber-js-mobile: 1.0.0 lodash-es: ^4.17.15 => 4.17.21 lodash.merge: ^4.6.2 => 4.6.2 lodash.snakecase: ^4.1.1 => 4.1.1 marked: ^1.2.5 => 1.2.9 (2.1.3) ng2-pdf-viewer: ^6.3.2 => 6.4.1 ngx-build-plus: ^12.0.1 => 12.0.1 ngx-webcam: ^0.3.2 => 0.3.2 node-example: 1.0.0 object.fromentries: ^2.0.2 => 2.0.4 prettier-eslint: ^12.0.0 => 12.0.0 prompt-sync: ^4.2.0 => 4.2.0 protractor: ~7.0.0 => 7.0.0 protractor-example: 1.0.0 rxjs: ~6.6.6 => 6.6.7 (6.4.0, 6.5.4) rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/internal-compatibility: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () s-ago: ^2.2.0 => 2.2.0 scully-plugin-minify-html: ^6.0.0 => 6.0.0 stripe: ^8.169.0 => 8.169.0 svg-inline-loader: ^0.8.2 => 0.8.2 tmp: ^0.1.0 => 0.1.0 (0.2.1, 0.0.33, 0.0.30) ts-node: ~8.3.0 => 8.3.0 (10.0.0) tslib: ^2.0.0 => 2.3.0 (1.14.1) typescript: ~4.3.5 => 4.3.5 (4.3.4, 3.9.10) typescript-example: 1.0.0 uuid: ^8.3.1 => 8.3.2 (3.4.0) webpack-bundle-analyzer: ^4.4.2 => 4.4.2 which: ^2.0.2 => 2.0.2 (1.3.1) xmlbuilder: ^15.1.1 => 15.1.1 (9.0.7, 11.0.1) yamljs: ^0.3.0 => 0.3.0 zone-mix: undefined () zone-node: undefined () zone-testing: undefined () zone.js: ~0.11.4 => 0.11.4 (0.10.3) zone.js/async-test: undefined () zone.js/async-test.min: undefined () zone.js/fake-async-test: undefined () zone.js/fake-async-test.min: undefined () zone.js/jasmine-patch: undefined () zone.js/jasmine-patch.min: undefined () zone.js/long-stack-trace-zone: undefined () zone.js/long-stack-trace-zone.min: undefined () zone.js/mocha-patch: undefined () zone.js/mocha-patch.min: undefined () zone.js/proxy: undefined () zone.js/proxy.min: undefined () zone.js/sync-test: undefined () zone.js/sync-test.min: undefined () zone.js/task-tracking: undefined () zone.js/task-tracking.min: undefined () zone.js/webapis-media-query: undefined () zone.js/webapis-media-query.min: undefined () zone.js/webapis-notification: undefined () zone.js/webapis-notification.min: undefined () zone.js/webapis-rtc-peer-connection: undefined () zone.js/webapis-rtc-peer-connection.min: undefined () zone.js/webapis-shadydom: undefined () zone.js/webapis-shadydom.min: undefined () zone.js/wtf: undefined () zone.js/wtf.min: undefined () zone.js/zone-bluebird: undefined () zone.js/zone-bluebird.min: undefined () zone.js/zone-error: undefined () zone.js/zone-error.min: undefined () zone.js/zone-legacy: undefined () zone.js/zone-legacy.min: undefined () zone.js/zone-patch-canvas: undefined () zone.js/zone-patch-canvas.min: undefined () zone.js/zone-patch-cordova: undefined () zone.js/zone-patch-cordova.min: undefined () zone.js/zone-patch-electron: undefined () zone.js/zone-patch-electron.min: undefined () zone.js/zone-patch-fetch: undefined () zone.js/zone-patch-fetch.min: undefined () zone.js/zone-patch-jsonp: undefined () zone.js/zone-patch-jsonp.min: undefined () zone.js/zone-patch-message-port: undefined () zone.js/zone-patch-message-port.min: undefined () zone.js/zone-patch-promise-test: undefined () zone.js/zone-patch-promise-test.min: undefined () zone.js/zone-patch-resize-observer: undefined () zone.js/zone-patch-resize-observer.min: undefined () zone.js/zone-patch-rxjs: undefined () zone.js/zone-patch-rxjs-fake-async: undefined () zone.js/zone-patch-rxjs-fake-async.min: undefined () zone.js/zone-patch-rxjs.min: undefined () zone.js/zone-patch-socket-io: undefined () zone.js/zone-patch-socket-io.min: undefined () zone.js/zone-patch-user-media: undefined () zone.js/zone-patch-user-media.min: undefined () npmGlobalPackages: @angular/cli: 12.1.1 @aws-amplify/cli: 7.4.4 firebase-tools: 9.8.0 local-web-server: 4.2.1 npm: 7.19.1 ```

Describe the bug

Sentry in my web app is reporting the following error on a few Android devices: "Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'byteLength') TypeError: Cannot read properties of undefined (reading 'byteLength')"

It seems this error is thrown when the device has network issues - a bunch of get rest api and cognito requests return http status 0 sentry shows (no response).

It seems isEmptyData in the aws-crypto lib should handle the case where data is undefined and return true for that as well.

exports.isEmptyData = void 0;
function isEmptyData(data) {
    if (typeof data === "string") {
        return data.length === 0;
    }

    return data.byteLength === 0;
}

Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'byteLength') TypeError: Cannot read prop… 2021-11-21 16-19-54

Expected behavior

Code shouldn't fail if there is network issue.

Reproduction steps

Unknown, I just see the error in Sentry (3 users so far), and they are all running Android.

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

ZOICloudServicesCompany commented 2 years ago

we are having the same issue.

GeorgeBellTMH commented 2 years ago

I am getting this in react...it is blocking our tests from running in cypress...any updates?

tuan43 commented 2 years ago

still getting this issue. any updates?

cwomack commented 1 year ago

@hisham, can you clarify what calls are being made when this occurs? I've seen this error pop up in different issues, but it's notorious for being difficult to reproduce without more information about the specific calls being made or more information about your environment. Usually this happens with Storage or Auth libraries in particular, so can you confirm if you're using either of those?

It doesn't appear to be specific to Angular per @GeorgeBellTMH's comment about experiencing this in React as well, but I'm having trouble reproducing this reliably.

Possibly related issues: #10381 #10809 (and quite a few closed issues)

hisham commented 1 year ago

Hi @cwomack - my apologies for delay in responding. The error always happens after a call to cognito (see attached screenshot). It's happening for a minority of users once every day or few days.

This part of our app where this error occurs is public btw. It happens in these urls - https://www.essentialclinic.ca/hair-loss-visit and https://www.essentialclinic.ca/ed-visit. Network requests to API Gateway and Pinpoint are made in these pages, and user also uploads photos to an s3 guest bucket (public write, no read). No authentication is required for these requests. However I think the loading of the S3 storage service in aws-amplify triggers the call to cognito as it needs an identity id. And for some reason that call to cognito sometimes fails for some users, probably due to poor network connection on the user's part. You can see the call to cognito is made whenever these pages load in the below attached screenshot.

I hope this helps, let me know if anything else is needed.

CleanShot 2023-02-21 at 12 13 22@2x

CleanShot 2023-02-21 at 12 25 53@2x
cwomack commented 1 year ago

@hisham, appreciate the reply and additional context. Are you able to share what your IAM permissions look like for the Cognito Identity Pool tied to unauthenticated users?

hisham commented 1 year ago

Yes I can share it but I should probably not post it publicly here. Is there an email like amplify-cli@amazon.com that I can send to?

cwomack commented 1 year ago

@hisham, unfortunately there isn't a specific email address for the JS team or this repo at this point. However we can have customer calls through our Slack channels or even a screen share now through the Discord server for Amplify. Is there a preference you'd have between those?

hisham commented 1 year ago

Amplify has a Slack channel? I didn't know that. I prefer Slack but I'm on the Discord Amplify channel too - hisham#6667 is my username.

cwomack commented 1 year ago

Discord would be preferred! I'll ping you on there to follow up on this further. Any workaround/solution we can post back on this issues (for anyone else that might be following).

nadetastic commented 1 year ago

Related to #11251

TrekSoft commented 1 year ago

Any update here? This is affecting our production users as well.

In the meantime, has anyone figured out what the workaround is - would it be to force the users who encounter it to login again? Or could they just retry and it's random if it works?

cwomack commented 1 year ago

Hey @TrekSoft. We don't have an update yet and are still trying to reproduce this issue reliably in order to find the source. Any additional context around specific steps to reproduce this issue, the methods being called, or especially a sample repo would be helpful.

TrekSoft commented 1 year ago

Unfortunately we don't have specific steps and it seems to be an edge case when it happens but similar to @hisham it happens in two locations in our app where users are uploading an image to S3.

Here's what the engineer investigating it wrote:

We got this issue when trying to get the current session with Auth.currentSession(). This method will automatically get the accessToken and idToken from AWS Cognito. But we got an error while calling Cognito: "PreTokenGeneration invocation failed due to error Socket timeout while invoking Lambda function". And Amplify throws an error message "Cannot read property 'byteLength' of undefined"

TrekSoft commented 1 year ago

Any update on this? This has affected 9 users in the past 5 days and is a really horrible experience for them when it happens.

TrekSoft commented 1 year ago

As some additional, potentially helpful information, on iOS it automatically triggers a logout but on Android it doesn't and all other actions the user attempts to take after that point fail with the same error.

nadetastic commented 11 months ago

Hi @TrekSoft following up here. Can you clarify what action is being attempted when this error occurs? For example, is the user attempting to get an object from Storage?

nadetastic commented 11 months ago

Hi @TrekSoft - let me know if you still need assistance with this issue.

TrekSoft commented 11 months ago

Sorry yeah no more assistance needed here. We were attempting to read a file from s3 while the user's token was expired.

On Fri, Oct 6, 2023, 5:33 PM Dan Kiuna @.***> wrote:

Hi @TrekSoft https://github.com/TrekSoft - let me know if you still need assistance with this issue.

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9265#issuecomment-1751426974, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGZTBRUFSDPAH43RUBHLATX6B2LXAVCNFSM5IPWKVHKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZVGE2DENRZG42A . You are receiving this because you were mentioned.Message ID: @.***>

nadetastic commented 10 months ago

Hi @hisham following up here - let me know if you are still having this issue as it may have been related to missing permissions on the user.

hisham commented 10 months ago

haven't seen it in a while, so feel free to close, thanks!

cwomack commented 10 months ago

@hisham, that's great to hear! We'll close this issue out then, but definitely take a look at our release announcement for the latest version of Amplify, migration guide, and documentation for more information.