Fix Nomad event stream is ignoring errors

when an event stream could be established once.
This commit is contained in:
Maximilian Paß
2022-09-07 07:06:09 +02:00
parent e8457ca035
commit 89fc7b2637
3 changed files with 23 additions and 3 deletions

View File

@ -211,11 +211,10 @@ type nomadAPIEventHandler func(event *nomadApi.Event) (done bool, err error)
func receiveAndHandleNomadAPIEvents(stream <-chan *nomadApi.Events, handler nomadAPIEventHandler) error {
// If original context is canceled, the stream will be closed by Nomad and we exit the for loop.
for events := range stream {
if events.IsHeartbeat() {
continue
}
if err := events.Err; err != nil {
return fmt.Errorf("error receiving events: %w", err)
} else if events.IsHeartbeat() {
continue
}
for _, event := range events.Events {
// Don't take the address of the loop variable as the underlying value might change