-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ripgrep breaks while read loop. maybe stdin detection issue? #1219
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
Comments
For As for behavior on master... I'm not sure what's going on actually. At first I thought it might be because you were executing a search with no results, and therefore would get a
I couldn't imagine how stdin detection would be impacted here, but it looks like you're right. We can test it by supplying a file path to search directly, which overrides stdin detection.
Any shell wizards want to explain this? :-) |
where is the code for the stdin detection? i tried
but unless i'm making some mistake, this doesn't reproduce the bug:
(maybe narrowing that down to a minimal example would give us some insights) |
That does appear to reproduce the bug though? That's saying that stdin is readable, which will in turn cause ripgrep to try to read stdin. Normally that manifests as ripgrep blocking on stdin, but my guess is that something is then immediately closing stdin which causes ripgrep to terminate without finding anything. The specific place where ripgrep does stdin detection is here: Lines 1188 to 1204 in 0913972
In this case, all four parts of that conditional are return false, which means ripgrep will try to search stdin. Interesting. |
For what it's worth, I tested this on zsh and it's also present there - so it's not limited to just bash |
ok so i wonder if what's happening is this: use std::io::{self, Read};
fn main() -> io::Result<()> {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer)?;
println!("read: '{}'", buffer);
Ok(())
} echo -e "foo\nbar" | while read flag; do echo "flag: $flag" && echo "rg: $(./target/debug/rg-bug $flag)" ; done
flag: foo
rg: read: 'bar
' |
As for why the loop stops, it's because
If you're using GNU A general work-around is to have your loop input go to a different file descriptor:
|
thanks @okdana ! (though in this case a nicer workaround might be to specify the path to override stdin detection) or i might just go back to thanks again for your helpful explanation will close as it seems ripgrep is working correctly |
Also just stumbled across this. Would it make sense for |
Why add a new flag when specifying the directory to search fixes the problem? Use |
Yes, it is what I ended up doing. I was thinking an option or some text in the |
What version of ripgrep are you using?
testing
and
How did you install ripgrep?
homebrew / git + compiled manually
What operating system are you using ripgrep on?
osx 10.14.2
Describe your question, feature request, or bug.
I'm getting surprising behaviours calling
ripgrep
inside awhile read
loopIf this is a bug, what are the steps to reproduce the behavior?
[empty dir]
0.10.0 from homebrew (full -v above)
master manually compiled (full -v above)
(n.b. aborts the while loop;
flag: bar
is missing)If this is a bug, what is the actual behavior?
repeat of the above with
--debug
(makes it hard to see the regular output)0.10.0 from homebrew (full -v above)
master manually compiled (full -v above)
If this is a bug, what is the expected behavior?
on master, i would expect the while loop to continue, (on 0.10.0 am surprised by the
<stdin>: output kind PathWithMatch requires a file path
output)What do you think ripgrep should have done?
is there maybe still some issue with stdin detection?
The text was updated successfully, but these errors were encountered: