From 995413426c8302332bbec0c31a168eea50ed1052 Mon Sep 17 00:00:00 2001 From: Carlo Teubner Date: Tue, 9 Sep 2025 07:01:22 +0100 Subject: [PATCH] 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. --- client.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 702bdc36..949e07b6 100644 --- a/client.go +++ b/client.go @@ -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 }