Skip to content

Commit

Permalink
503 if node is not active
Browse files Browse the repository at this point in the history
If we get to respondStandby but we're actually not in an HA cluster, we
should instead indicate the correct status to the user. Although it
might be better to change any such behavior upstream, if any upstream
code manages this state we should still handle it correctly.

Fixes #4873
  • Loading branch information
jefferai committed Jul 6, 2018
1 parent c8ab530 commit da8dcd3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -422,13 +423,20 @@ func respondStandby(core *vault.Core, w http.ResponseWriter, reqURL *url.URL) {
// Request the leader address
_, redirectAddr, _, err := core.Leader()
if err != nil {
if err == vault.ErrHANotEnabled {
// Standalone node, serve 503
err = errors.New("node is not active")
respondError(w, http.StatusServiceUnavailable, err)
return
}

respondError(w, http.StatusInternalServerError, err)
return
}

// If there is no leader, generate a 503 error
if redirectAddr == "" {
err = fmt.Errorf("no active Vault instance found")
err = errors.New("no active Vault instance found")
respondError(w, http.StatusServiceUnavailable, err)
return
}
Expand Down

0 comments on commit da8dcd3

Please sign in to comment.