Skip to content

Commit

Permalink
nil check and error handling for client status in heartbeat responses
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycub committed May 25, 2023
1 parent 9ff1d92 commit 24efcc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,8 @@ func (c *Client) updateNodeStatus() error {
}

// Check heartbeat response for information about the server-side scheduling
// state of this node
// state of this node. If there are errors on the server side, this will come
// back as an empty string.
c.UpdateConfig(func(c *config.Config) {
if resp.SchedulingEligibility != "" {
c.Node.SchedulingEligibility = resp.SchedulingEligibility
Expand Down
13 changes: 11 additions & 2 deletions nomad/node_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,17 @@ func (n *Node) constructNodeServerInfoResponse(nodeID string, snap *state.StateS
}

// Add ClientStatus information to heartbeat response.
node, _ := snap.NodeByID(nil, nodeID)
reply.SchedulingEligibility = node.SchedulingEligibility
if node, err := snap.NodeByID(nil, nodeID); err == nil && node != nil {
reply.SchedulingEligibility = node.SchedulingEligibility
} else if err != nil {
// emit an error to the log and leave the string as empty, which is treated
// as a no-op in the client response handler.
n.logger.Error("constructNodeServerInfoResponse: error fetching node by id",
"node_id", nodeID, "err", err)
} else {
n.logger.Error("constructNodeServerInfoResponse: node==nil without error",
"node_id", nodeID)
}

// TODO(sean@): Use an indexed node count instead
//
Expand Down

0 comments on commit 24efcc1

Please sign in to comment.