mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-11 09:05:51 +08:00
fix: Fixed the issue that caused the error (bufio.Scanner: token too long) when viewing container log (#9256)
Refs https://github.com/1Panel-dev/1Panel/issues/9241
This commit is contained in:
parent
193ae2b7d6
commit
669855de70
1 changed files with 20 additions and 9 deletions
|
@ -958,7 +958,7 @@ func collectLogs(done <-chan struct{}, params dto.StreamLog, messageChan chan<-
|
|||
}
|
||||
}()
|
||||
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
reader := bufio.NewReader(stdout)
|
||||
|
||||
processKilled := false
|
||||
go func() {
|
||||
|
@ -972,19 +972,30 @@ func collectLogs(done <-chan struct{}, params dto.StreamLog, messageChan chan<-
|
|||
}
|
||||
}()
|
||||
|
||||
for scanner.Scan() {
|
||||
message := scanner.Text()
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if len(line) > 0 {
|
||||
line = strings.TrimSuffix(line, "\n")
|
||||
select {
|
||||
case messageChan <- line:
|
||||
case <-done:
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
errorChan <- fmt.Errorf("reader error: %v", err)
|
||||
return
|
||||
}
|
||||
line = strings.TrimSuffix(line, "\n")
|
||||
select {
|
||||
case messageChan <- message:
|
||||
case messageChan <- line:
|
||||
case <-done:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = scanner.Err(); err != nil && err != io.EOF {
|
||||
errorChan <- fmt.Errorf("scanner error: %v", err)
|
||||
}
|
||||
|
||||
_ = dockerCmd.Wait()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue