Check for error before prefix; fixes abandoned routine; closes pterodactyl/panel#3911
Due to the order of the previous logic in ScanReader, an error not caused by EOF would effectively get ignored since an error will always be returned with `isPrefix` equal to false, thus triggering the first break, and error checking is not performed beyond that point. Thus, canceling an installation process for a server while this process was running would hang the routine and cause the loop to run endlessly, even with a canceled context.
This commit is contained in:
@@ -88,16 +88,16 @@ func ScanReader(r io.Reader, callback func(line []byte)) error {
|
||||
} else {
|
||||
buf.Write(line)
|
||||
}
|
||||
// If we encountered an error with something in ReadLine that was not an
|
||||
// EOF just abort the entire process here.
|
||||
if err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
// Finish this loop and begin outputting the line if there is no prefix
|
||||
// (the line fit into the default buffer), or if we hit the end of the line.
|
||||
if !isPrefix || err == io.EOF {
|
||||
break
|
||||
}
|
||||
// If we encountered an error with something in ReadLine that was not an
|
||||
// EOF just abort the entire process here.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Send the full buffer length over to the event handler to be emitted in
|
||||
|
||||
Reference in New Issue
Block a user