Skip to content

Commit

Permalink
ais: fix node-join return values to avoid panic
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
VirrageS authored and alex-aizman committed Jul 26, 2024
1 parent dc551e6 commit 21cce48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
17 changes: 10 additions & 7 deletions ais/htrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ func (h *htrun) extractRevokedTokenList(payload msPayload, caller string) (*toke
// - if these fails we try the candidates provided by the caller.
//
// ================================== Background =========================================
func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res *callResult) {
func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res *callResult, err error) {
var (
config = cmn.GCO.Get()
candidates = make([]string, 0, 4+len(contactURLs))
Expand Down Expand Up @@ -1817,7 +1817,7 @@ func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res
for range 4 { // retry
for _, candidateURL := range candidates {
if nlog.Stopping() {
return
return res, errors.New(h.String() + " is stopping")
}
if resPrev != nil {
freeCR(resPrev)
Expand All @@ -1837,20 +1837,23 @@ func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res
}

smap := h.owner.smap.get()
if smap.validate() != nil {
return
if err := smap.validate(); err != nil {
return res, fmt.Errorf("%s: invalid Smap, err: %v", h.si, err)
}

// Failed to join cluster using config, try getting primary URL using existing smap.
nsti, _ := h.bcastHealth(smap, false /*checkAll*/)
if nsti == nil || nsti.Smap.Version < smap.version() {
return
if nsti == nil {
return res, fmt.Errorf("%s: failed to discover a new smap", h)
}
if nsti.Smap.Version < smap.version() {
return res, fmt.Errorf("%s: current %s version is newer than %d from the primary proxy (%s)", h, smap, nsti.Smap.Version, nsti.Smap.Primary.ID)
}
primaryURL = nsti.Smap.Primary.PubURL

// Daemon is stopping skip register
if nlog.Stopping() {
return
return res, errors.New(h.String() + " is stopping")
}
res = h.regTo(primaryURL, nil, apc.DefaultTimeout, query, htext, false /*keepalive*/)
if res.err == nil {
Expand Down
8 changes: 5 additions & 3 deletions ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,13 @@ func (p *proxy) joinCluster(action string, primaryURLs ...string) (status int, e
if cmn.GCO.Get().Proxy.NonElectable {
query = url.Values{apc.QparamNonElectable: []string{"true"}}
}
res := p.join(query, nil /*htext*/, primaryURLs...)
res, err := p.join(query, nil /*htext*/, primaryURLs...)
if err != nil {
return status, err
}
defer freeCR(res)
if res.err != nil {
status, err = res.status, res.err
return
return res.status, res.err
}
// not being sent at cluster startup and keepalive
if len(res.bytes) == 0 {
Expand Down
8 changes: 5 additions & 3 deletions ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ type delb struct {
}

func (t *target) joinCluster(action string, primaryURLs ...string) (status int, err error) {
res := t.join(nil, t, primaryURLs...)
res, err := t.join(nil, t, primaryURLs...)
if err != nil {
return status, err
}
defer freeCR(res)
if res.err != nil {
status, err = res.status, res.err
return
return res.status, res.err
}
// not being sent at cluster startup and keepalive
if len(res.bytes) == 0 {
Expand Down

0 comments on commit 21cce48

Please sign in to comment.