aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
164 stars 56 forks source link

npx amplify sandbox contrl+c not handled properly #932

Open lazpavel opened 8 months ago

lazpavel commented 8 months ago

Environment information

System:
    OS: Linux 6.7 Arch Linux
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i9-12900HX
    Memory: 114.74 GB / 125.50 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.21 - /usr/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
    pnpm: 8.14.1 - ~/.local/share/pnpm/pnpm
    bun: Not Found
    Watchman: Not Found
  npmPackages:
    @aws-amplify/backend: ^0.10.1 => 0.10.1 
    @aws-amplify/backend-cli: ^0.9.6 => 0.9.6 
    aws-amplify: ^6.0.12 => 6.0.12 
    aws-cdk: ^2.121.1 => 2.121.1 
    aws-cdk-lib: ^2.121.1 => 2.121.1 
    typescript: ^5.2.0 => 5.3.3

Description

npx amplify sandbox process not exiting gracefully on control + c. It behaves randomly incorrect

  1. not listening to control + c event when npx amplify sandbox is in error state image

  2. control + c event skips all the way without letting me respond to cleanup prompt image

Most of the time this behavior happens when deploying sandbox env errors but occastionally noticed it on success as well.

josefaidt commented 8 months ago

I'm able to reproduce this by removing email from the defineAuth template, running amplify sandbox, which in turn produces an error. When attempting to ctrl+c I see the same issue

➜  p amplify sandbox

Unable to build Amplify backend. Check your backend definition in the `amplify` folder.
Caused By: Bundling asset amplify-amplifygen2-josef-sandbox-b6eddb8592/auth/SecretFetcherResourceProviderLambda/Code/Stage...

  ...3091233f22ea8ed624b7d06d4a2170d6d2865d8d59e2577d6547e30/index.js  204.2kb

⚡ Done in 83ms
/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:358
      throw Error('At least one of email or phone must be enabled.');
            ^

Error: At least one of email or phone must be enabled.
    at AmplifyAuth.AmplifyAuth.getUserPoolProps (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:358:13)
    at AmplifyAuth (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:118:39)
    at AmplifyAuthGenerator.generateContainerEntry (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend-auth@0.4.4_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend-auth/src/factory.ts:93:27)
    at SingletonConstructContainer.getOrCompute (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/engine/singleton_construct_container.ts:45:19)
    at AmplifyAuthFactory.getInstance (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend-auth@0.4.4_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend-auth/src/factory.ts:67:31)
    at <anonymous> (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:92:68)
    at Array.forEach (<anonymous>)
    at BackendFactory (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:88:40)
    at defineBackend (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:120:19)
    at <anonymous> (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/amplify/backend.ts:4:17)

Node.js v20.11.0
Subprocess exited with error 1

[Sandbox] Watching for file changes...
[Sandbox] Initializing...
[Sandbox] Executing command `deploy`

Unable to build Amplify backend. Check your backend definition in the `amplify` folder.
Caused By: Bundling asset amplify-amplifygen2-josef-sandbox-b6eddb8592/auth/SecretFetcherResourceProviderLambda/Code/Stage...

  ...3091233f22ea8ed624b7d06d4a2170d6d2865d8d59e2577d6547e30/index.js  204.2kb

⚡ Done in 13ms
/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:358
      throw Error('At least one of email or phone must be enabled.');
            ^

Error: At least one of email or phone must be enabled.
    at AmplifyAuth.AmplifyAuth.getUserPoolProps (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:358:13)
    at AmplifyAuth (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+auth-construct-alpha@0.5.3_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/auth-construct-alpha/src/construct.ts:118:39)
    at AmplifyAuthGenerator.generateContainerEntry (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend-auth@0.4.4_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend-auth/src/factory.ts:93:27)
    at SingletonConstructContainer.getOrCompute (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/engine/singleton_construct_container.ts:45:19)
    at AmplifyAuthFactory.getInstance (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend-auth@0.4.4_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend-auth/src/factory.ts:67:31)
    at <anonymous> (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:92:68)
    at Array.forEach (<anonymous>)
    at BackendFactory (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:88:40)
    at defineBackend (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/node_modules/.pnpm/@aws-amplify+backend@0.10.2_aws-cdk-lib@2.123.0_constructs@10.3.0_zod@3.22.4/node_modules/@aws-amplify/backend/src/backend_factory.ts:120:19)
    at <anonymous> (/Users/josef/Documents/projects/aws-amplify/amplify-gen2-app/amplify/backend.ts:4:17)

Node.js v20.11.0
Subprocess exited with error 1

[Sandbox] Watching for file changes...
^C[Sandbox] Shutting down
? Would you like to delete all the resources in your sandbox environment (This 
cannot be undone)? (y/N) [Sandbox] Shutting down

Error: setRawMode EIO
josefaidt commented 8 months ago

reproduced the second issue where the sandbox is hanging on to the process. I think my sso session expired and I saved a change in auth, then encountered the error below. When I encounter this I am forced to close my terminal.

The CloudFormation deployment has failed. Find more information in the CloudFormation AWS Console for this stack.
Caused By: ❌ Deployment failed: Error: Unable to resolve AWS account to use. It must be either configured when you define your CDK Stack, or through the environment

[Sandbox] Watching for file changes...
^C^X^C^C^C^C^C^C^C

^C^C^C
Amplifiyer commented 5 months ago

The issue is with the yarn not respecting SIGINT signal and just exiting right away leaving the children (sandbox process) hanging. because the parent process (yarn) is exited, the associated STDIO for child are also closed, so when the prompt tries to send something to stdout it crashes with the error setRawMode EIO.

I had better luck with yarn 1.22.22 where atleast the shell didn't hang and was still usable. but doesn't look like we can do anything until yarn fixes that bug.