-
Notifications
You must be signed in to change notification settings - Fork 68
Move to bufio reader to support larger tokens #273
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
Conversation
internal/supervisor/output.go
Outdated
line, err := reader.ReadBytes('\n') | ||
if err != nil { | ||
// EOF is expected, so don't log it | ||
if err != io.EOF { | ||
log.Printf("reader error: %v", err) | ||
} | ||
break | ||
} | ||
m.WriteLine(proc, line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs, line
may be non-empty even in case of an error (e.g. if the last output line is not terminated by \n
), so may be worth piping it through regardless:
line, err := reader.ReadBytes('\n') | |
if err != nil { | |
// EOF is expected, so don't log it | |
if err != io.EOF { | |
log.Printf("reader error: %v", err) | |
} | |
break | |
} | |
m.WriteLine(proc, line) | |
line, err := reader.ReadBytes('\n') | |
if len(line) > 0 { | |
m.WriteLine(proc, line) | |
} | |
if err != nil { | |
// EOF is expected, so don't log it | |
if err != io.EOF { | |
log.Printf("reader error: %v", err) | |
} | |
break | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more thing, ReadBytes
keeps the terminator in the returned line
, so WriteLine
may need to account for it:
buf.WriteString("\033[0m | ")
buf.Write(p)
- buf.WriteByte('\n')
+ if p[len(p)-1] != '\n' {
+ buf.WriteByte('\n')
+ }
m.mutex.Lock()
defer m.mutex.Unlock()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@immerrr Thanks for the assist! |
Works to address: #272