Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 42d9567

Browse files
committed
Merge pull request #664 from jcooklin/ib/662-task-hang
Fix #662: Task hangs on a large number of metrics
2 parents 6fc20b4 + 7b1c532 commit 42d9567

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

control/plugin/execution.go

+20
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ func waitForPluginTimeout(timeout time.Duration, p pluginExecutor, waitChannel c
276276
func waitForResponseFromPlugin(r io.Reader, waitChannel chan waitSignalValue, logpath string) {
277277
lp := strings.TrimSuffix(logpath, filepath.Ext(logpath))
278278
lf, _ := os.OpenFile(lp+".stdout", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
279+
defer lf.Close()
279280
logger := log.New(lf, "", log.Ldate|log.Ltime)
280281
processedResponse := false
281282
scanner := bufio.NewScanner(r)
282283
resp := new(Response)
283284
// scan until we get a response or reader is closed
285+
OK:
284286
for scanner.Scan() {
285287
if !processedResponse {
286288
// Get bytes
@@ -303,16 +305,34 @@ func waitForResponseFromPlugin(r io.Reader, waitChannel chan waitSignalValue, lo
303305
logger.Println(scanner.Text())
304306
}
305307
}
308+
if err := scanner.Err(); err != nil {
309+
if err == bufio.ErrTooLong {
310+
reader := bufio.NewReader(r)
311+
logger.Println(reader.ReadLine())
312+
goto OK
313+
}
314+
logger.Println(err)
315+
}
306316
}
307317

308318
func logStdErr(r io.Reader, logpath string) {
309319
lp := strings.TrimSuffix(logpath, filepath.Ext(logpath))
310320
lf, _ := os.OpenFile(lp+".stderr", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
321+
defer lf.Close()
311322
logger := log.New(lf, "", log.Ldate|log.Ltime)
312323
scanner := bufio.NewScanner(r)
324+
OK:
313325
for scanner.Scan() {
314326
logger.Println(scanner.Text())
315327
}
328+
if err := scanner.Err(); err != nil {
329+
if err == bufio.ErrTooLong {
330+
reader := bufio.NewReader(r)
331+
logger.Println(reader.ReadLine())
332+
goto OK
333+
}
334+
logger.Println(err)
335+
}
316336
}
317337

318338
func waitForKilledPlugin(p pluginExecutor, waitChannel chan waitSignalValue) {

plugin/publisher/snap-publisher-file/file/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (f *filePublisher) Publish(contentType string, content []byte, config map[s
6464
return errors.New(fmt.Sprintf("Unknown content type '%s'", contentType))
6565
}
6666

67-
logger.Printf("publishing %v to %v", metrics, config)
67+
logger.Printf("publishing %v metrics to %v", len(metrics), config)
6868
file, err := os.OpenFile(config["file"].(ctypes.ConfigValueStr).Value, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
6969
defer file.Close()
7070
if err != nil {

0 commit comments

Comments
 (0)