Skip to content

Commit

Permalink
consul: handle nil multierror pointer correctly
Browse files Browse the repository at this point in the history
When the service client syncs to Consul, we accumulate service sync errors in a
multierror before reading all the local checks. If the API call to the local
checks fails, we either return that error or append it to the multierror and
return the set of errors. But `multierror.Error.Len()` doesn't nil-check, so we
need to do this ourselves.

I've also made a quick pass through the rest of the code base looking for
multierror `Len` method calls to see if we have this pattern elsewhere.

Fixes: #24512
  • Loading branch information
tgross committed Nov 20, 2024
1 parent 25cc492 commit d32fc92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/24513.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
consul: Fixed a bug where failures when syncing Consul checks could panic the Nomad agent
```
2 changes: 1 addition & 1 deletion command/agent/consul/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ func (c *ServiceClient) sync(reason syncReason) error {
if err != nil {
metrics.IncrCounter([]string{"client", "consul", "sync_failure"}, 1)
err = fmt.Errorf("failed to query Consul checks: %w", err)
if mErr.Len() == 0 {
if mErr == nil || mErr.Len() == 0 {
return err
} else {
mErr = multierror.Append(mErr, err)
Expand Down

0 comments on commit d32fc92

Please sign in to comment.