junegunn / junegunn/fzf

child processes are not terminated - output redirection unusable

Open
#1,702 1 comment 0 reactions 0 assignees View on GitHub
help-needed windows
Dominant language
Go
Stars
83k
Forks
2.9k
Avg merge
17h 8m
Merged PRs (30d)
10

Description

- Category
- [x] fzf binary
- [ ] fzf-tmux script
- [ ] Key bindings
- [ ] Completion
- [ ] Vim
- [ ] Neovim
- [x] Etc.
- OS
- [ ] Linux
- [ ] Mac OS X
- [x] Windows
- [ ] Windows Subsystem for Linux
- [ ] Etc.
- Shell
- [ ] bash
- [ ] zsh
- [ ] fish
- [x] powershell / cmd

I've been using fzf on Windows for a while now, but always had trouble when using it with "deeply nested" directory trees.

## fzf version
![image](https://user-images.githubusercontent.com/5354972/65761128-864d6b80-e11e-11e9-8455-2167c5784310.png)
(installed via Chocolatey)

## context
I'm using a PowerShell helper `cd-fzf` which basically calls fzf and tries to do a `set-location` on the result:
```
function cd-fzf {
Set-Location (Get-Item $(fzf)).Directory.FullName
}
```

## a simpler example
you should be able to redirect the output of fzf to a variable:
```
$res = $(fzf)
```

## the problem
the above stated examples work all right, iff the current working directory is not "deep", i.e. the child process that's doing the search in the background is able to finish at some point.

I've noticed, that `fzf.exe` finishes on press of enter, yet a "leftover" `cmd.exe` runs as long as it needs to list all files in the current directory.

## proof

Screenshot 1: (procexp) fzf during runtime, notice the child `cmd.exe` with pid 1180
![1](https://user-images.githubusercontent.com/5354972/65760644-ae889a80-e11d-11e9-8b51-520391926870.PNG)

Screenshot 2: after fzf finished, the child `cmd.exe` with pid 1180 keeps running,
![2](https://user-images.githubusercontent.com/5354972/65760731-d5df6780-e11d-11e9-81b3-022b2873a0ac.PNG)

- as long as the child process is not being destroyed, the output redirection `$somevar = $(fzf)` hangs.

## suggested fix

actively kill all child processes before exiting `fzf`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue on Windows using the reported PowerShell examples, especially `$res = $(fzf)` and a deeply nested directory tree. Trace how fzf starts and exits its background search process, then verify that child processes are terminated before exit and output redirection no longer hangs.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, powershell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.