lf -remote: work around busyloop issue on Linux (#2138)

I noticed that running ":maps" in lf on Linux uses a whole CPU. I
managed to track it down to a bug in the Go standard library, for which
I entered https://github.com/golang/go/issues/75304.

Until that is fixed, it seems worth having a workaround for this.
This commit is contained in:
Carlo Teubner authored and GitHub committed 2025-09-09 16:01:22 +10:00
1 parent b73daad7cc
commit 995413426c
1 file changed
+10 -2
+10 -2
View File
@@ -182,9 +182,17 @@ func remote(cmd string) error {
v.CloseWrite()
}
io.Copy(os.Stdout, c)
// The most straightforward way to write the reponse to stdout would be
// to do "io.Copy(os.Stdout, c)". However, on Linux, if stdout is connected to
// something like a pager that isn't immediately reading everything,
// this runs into Go bug https://github.com/golang/go/issues/75304 and
// busy-loops, eating a whole CPU.
response, err := io.ReadAll(c)
if err != nil {
return fmt.Errorf("reading response from server: %w", err)
}
c.Close()
os.Stdout.Write(response)
return nil
}