Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout to avoid long-term hangs #2546

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
frankcalise marked this conversation as resolved.
Show resolved Hide resolved
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