Skip to content

Fix --no-input hang when stdin is a socket or non-pipe fd - #1016

Open
harriiinnii wants to merge 2 commits into
ankitpokhrel:mainfrom
harriiinnii:fix/stdin-non-tty-hang
Open

Fix --no-input hang when stdin is a socket or non-pipe fd#1016
harriiinnii wants to merge 2 commits into
ankitpokhrel:mainfrom
harriiinnii:fix/stdin-non-tty-hang

Conversation

@harriiinnii

Copy link
Copy Markdown

Problem

jira issue create --no-input (and jira issue comment add --no-input) hangs indefinitely when the process is invoked from a subprocess context where stdin is a Unix socket pair, a character device, or any other non-pipe, non-file fd.

StdinHasData() returned true for any non-terminal fd:

func StdinHasData() bool {
    return !term.IsTerminal(int(os.Stdin.Fd()))
}

This caused ReadFile("") to call io.ReadAll(os.Stdin) and block forever, because socket pairs only return EOF when the peer explicitly shuts down the write half — which automation tools typically do not do.

Fix

Narrow the StdinHasData() check so it returns true only when stdin is a named pipe (os.ModeNamedPipe) or a regular file (mode.IsRegular()). This matches the actual intent — "did the caller pipe or redirect data?" — and leaves sockets, character devices, and other special files returning false.

func StdinHasData() bool {
    if term.IsTerminal(int(os.Stdin.Fd())) {
        return false
    }
    fi, err := os.Stdin.Stat()
    if err != nil {
        return false
    }
    mode := fi.Mode()
    return mode&os.ModeNamedPipe != 0 || mode.IsRegular()
}

Both common use cases continue to work as before:

  • echo "body" | jira issue create ... — pipe, returns true
  • jira issue create ... < body.txt — regular file, returns true

Fixes #948
Fixes #984

StdinHasData() returned true for any non-terminal fd, including Unix
socket pairs and character devices. This caused --no-input commands
(e.g. `jira issue create`) to call io.ReadAll(os.Stdin) and block
forever on a socket that never sends EOF.

Narrow the check so only pipes (ModeNamedPipe) and regular files are
treated as having data. Terminals, sockets, character devices, and
other special files now return false, matching the expected semantics
of "is there piped/redirected data ready to read?".

Fixes ankitpokhrel#948
Fixes ankitpokhrel#984
The previous commit accidentally stripped � from the color format
strings in Success(), Warn(), and Fail(). Those functions were not part
of the intended change and are restored verbatim from the base.

The only functional change is StdinHasData(): narrow the non-terminal
check to named pipes and regular files so stdin sockets do not block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant