From 7f2f209569c85bf28d1c7eb6ebede2a39a9ad4ba Mon Sep 17 00:00:00 2001 From: zc Date: Fri, 4 Dec 2020 17:17:10 +0800 Subject: [PATCH] fix scan error on too long line (#290) --- rpc/rpc.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rpc/rpc.go b/rpc/rpc.go index efa4e798f..b32202bf5 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -807,12 +807,25 @@ func (v *Vibranium) RunAndWait(stream pb.CoreRPC_RunAndWaitServer) error { } } }() - scanner := bufio.NewScanner(r) - for scanner.Scan() { - log.Infof("[Async RunAndWait] %v", scanner.Text()) - } - if err := scanner.Err(); err != nil { - log.Errorf("Async RunAndWait] scan error: %v", err) + bufReader := bufio.NewReader(r) + for { + var ( + line, part []byte + isPrefix bool + err error + ) + for { + if part, isPrefix, err = bufReader.ReadLine(); err != nil { + log.Errorf("[Aysnc RunAndWait] read error: %+v", err) + return + } + line = append(line, part...) + if !isPrefix { + break + } + + } + log.Infof("[Async RunAndWait] %s", line) } }) }()