Skip to content

[Console] Ctrl-C can break the terminal when selecting input from a list #61732

@johnstevenson

Description

@johnstevenson

Symfony version(s) affected

7.3.3

Description

When using Symfony QuestionHelper and selecting input from a list of choices (ChoiceQuestion), Ctrl-C can leave the terminal in a broken state on Unixy platforms under certain conditions:

The terminal does not show any input and requires a Ctrl-Break and Enter to restart it.

When calling other QuestionHelper functions, Ctrl-C works okay.

Further info

When using a signal handler, this causes the terminal to break:

pcntl_signal(SIGINT, function ($signal) {
    echo 'CRTL_C received, exiting', PHP_EOL;
    exit(2;)
});

But this is okay:

pcntl_signal(SIGINT, function ($signal) {
    echo 'CRTL_C received - continuing', PHP_EOL;
});

When using a restart, SIGINT is set to be ignored in the parent process, then set to its default action in the restarted (child) process because it inherited the ignored state.

if (!self::$inRestart) {
    // Restarting, so ignore SIGINT in parent
    pcntl_signal(SIGINT, SIG_IGN);
} elseif (is_int(pcntl_signal_get_handler(SIGINT))) {
    // Restarted, no handler set so force default action
    pcntl_signal(SIGINT, SIG_DFL);
}

How to reproduce

Demo/reproducer: https://github.com/johnstevenson/sigbug

Possible Solution

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions