Skip to content

Commit

Permalink
Add timeout to avoid long-term hangs (#2546 by @jamonholmgren)
Browse files Browse the repository at this point in the history
* Add timeout to avoid long hangs

* Let's do 10 minutes to be safe

* Remove bun from CI for now

* Install bun

* Remove bun lockfile

* Adds --no-timeout flag

* fix(cli): no timeout switch

---------

Co-authored-by: Frank Calise <fcalise@gmail.com>
  • Loading branch information
jamonholmgren and frankcalise committed Nov 10, 2023
1 parent b231ae8 commit ca36ac7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
11 changes: 6 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ defaults: &defaults
working_directory: /mnt/ramdisk/repo

version: 2.1
orbs:
# https://circleci.com/developer/orbs/orb/cmgriffing/bun-orb
bun-orb: cmgriffing/bun-orb@0.0.26
jobs:
tests:
<<: *defaults
resource_class: large
steps:
- checkout
- bun-orb/setup:
version: 1.0.3
- run:
name: Install bun
command: curl -fsSL https://bun.sh/install | bash -s -- bun-v1.0.10
- run:
name: Link bun
command: sudo ln -s ~/.bun/bin/bun /usr/local/bin/
- restore_cache:
name: Restore node modules
keys:
Expand Down
1 change: 1 addition & 0 deletions docs/Ignite-CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Starts the interactive prompt for generating a new Ignite project. Any options n
- `--targetPath` string, specify a target directory where the project should be created
- `--removeDemo` will remove the boilerplate demo code after project creation
- `--useCache` flag specifying to use dependency cache for quicker installs
- `--no-timeout` flag to disable the timeout protection (useful for slow internet connections)
- `--yes` accept all prompt defaults

### Issue
Expand Down
24 changes: 24 additions & 0 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ export interface Options {
* Input Source: `prompt.ask`| `parameter.option`
*/
workflow?: Workflow
/**
* Whether or not to timeout if the app creation takes too long
* Input Source: `parameter.option`
* @default false
*/
noTimeout?: boolean
}

module.exports = {
Expand All @@ -148,11 +154,22 @@ module.exports = {
const options: Options = parameters.options

const yname = boolFlag(options.y) || boolFlag(options.yes)
const noTimeout = options.noTimeout ?? false
const useDefault = (option: unknown) => yname && option === undefined

const CMD_INDENT = " "
const command = (cmd: string) => p2(white(CMD_INDENT + cmd))

// Absolute maximum that an app can take after inputs
// is 10 minutes ... otherwise we've hung up somewhere and need to exit.
const MAX_APP_CREATION_TIME = 10 * 60 * 1000
const timeoutExit = () => {
p()
p(yellow("Error: App creation timed out."))
if (!debug) p(gray("Run again with --debug to see what's going on."))
process.exit(1)
}

// #endregion

// debug?
Expand Down Expand Up @@ -444,6 +461,9 @@ module.exports = {
// start tracking performance
const perfStart = new Date().getTime()

// add a timeout to make sure we don't hang on any errors
const timeout = noTimeout ? undefined : setTimeout(timeoutExit, MAX_APP_CREATION_TIME)

// #region Print Welcome
// welcome everybody!
const terminalWidth = process.stdout.columns ?? 80
Expand Down Expand Up @@ -753,6 +773,9 @@ module.exports = {
// we're done! round performance stats to .xx digits
const perfDuration = Math.round((new Date().getTime() - perfStart) / 10) / 100

// no need to timeout, we're done!
clearTimeout(timeout)

/** Add just a _little_ more spacing to match with spinners and heading */
const p2 = (m = "") => p(` ${m}`)

Expand All @@ -775,6 +798,7 @@ module.exports = {
useCache,
y: yname,
yes: yname,
noTimeout,
},
projectName,
toolbox,
Expand Down

0 comments on commit ca36ac7

Please sign in to comment.