agent: fix deadlock reading tokens from state

This commit is contained in:
Ryan Uber 2015-04-27 22:26:03 -07:00
parent 75d182296f
commit 23eab5ebcc
2 changed files with 4 additions and 6 deletions

View File

@ -538,7 +538,7 @@ func TestAgent_PersistService(t *testing.T) {
t.Fatalf("err: %s", err)
}
expected, err := json.Marshal(svc)
expected, err := json.Marshal(&persistedService{Service: svc})
if err != nil {
t.Fatalf("err: %s", err)
}

View File

@ -133,9 +133,8 @@ func (l *localState) AddServiceToken(id, token string) {
// ServiceToken returns the configured ACL token for the given
// service ID. If none is present, the agent's token is returned.
// Assumes a lock is already established on the state.
func (l *localState) ServiceToken(id string) string {
l.RLock()
defer l.RUnlock()
token := l.serviceTokens[id]
if token == "" {
token = l.config.ACLToken
@ -193,10 +192,9 @@ func (l *localState) AddCheckToken(id, token string) {
}
// CheckToken is used to return the configured health check token, or
// if none is configured, the default agent ACL token.
// if none is configured, the default agent ACL token. Assumes a lock
// has already been taken on the state.
func (l *localState) CheckToken(id string) string {
l.RLock()
defer l.RUnlock()
token := l.checkTokens[id]
if token == "" {
token = l.config.ACLToken