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

Commit

Permalink
Merge pull request #664 from jcooklin/ib/662-task-hang
Browse files Browse the repository at this point in the history
Fix #662: Task hangs on a large number of metrics
  • Loading branch information
jcooklin committed Jan 14, 2016
2 parents 6fc20b4 + 7b1c532 commit 42d9567
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions control/plugin/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ func waitForPluginTimeout(timeout time.Duration, p pluginExecutor, waitChannel c
func waitForResponseFromPlugin(r io.Reader, waitChannel chan waitSignalValue, logpath string) {
lp := strings.TrimSuffix(logpath, filepath.Ext(logpath))
lf, _ := os.OpenFile(lp+".stdout", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
defer lf.Close()
logger := log.New(lf, "", log.Ldate|log.Ltime)
processedResponse := false
scanner := bufio.NewScanner(r)
resp := new(Response)
// scan until we get a response or reader is closed
OK:
for scanner.Scan() {
if !processedResponse {
// Get bytes
Expand All @@ -303,16 +305,34 @@ func waitForResponseFromPlugin(r io.Reader, waitChannel chan waitSignalValue, lo
logger.Println(scanner.Text())
}
}
if err := scanner.Err(); err != nil {
if err == bufio.ErrTooLong {
reader := bufio.NewReader(r)
logger.Println(reader.ReadLine())
goto OK
}
logger.Println(err)
}
}

func logStdErr(r io.Reader, logpath string) {
lp := strings.TrimSuffix(logpath, filepath.Ext(logpath))
lf, _ := os.OpenFile(lp+".stderr", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
defer lf.Close()
logger := log.New(lf, "", log.Ldate|log.Ltime)
scanner := bufio.NewScanner(r)
OK:
for scanner.Scan() {
logger.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
if err == bufio.ErrTooLong {
reader := bufio.NewReader(r)
logger.Println(reader.ReadLine())
goto OK
}
logger.Println(err)
}
}

func waitForKilledPlugin(p pluginExecutor, waitChannel chan waitSignalValue) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/publisher/snap-publisher-file/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (f *filePublisher) Publish(contentType string, content []byte, config map[s
return errors.New(fmt.Sprintf("Unknown content type '%s'", contentType))
}

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

0 comments on commit 42d9567

Please sign in to comment.