Skip to content

Commit

Permalink
fix recusive rwmutex rlock which cause headscale deadlock
Browse files Browse the repository at this point in the history
Signed-off-by: fortitude.zhang <fortitude.zhang@gmail.com>
  • Loading branch information
fortitudepub committed Jan 23, 2024
1 parent 1e22f17 commit 670eb81
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hscontrol/db/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ func (hsdb *HSDatabase) GetAPIKey(prefix string) (*types.APIKey, error) {
return &key, nil
}

func (hsdb *HSDatabase) getAPIKey(prefix string) (*types.APIKey, error) {
key := types.APIKey{}
if result := hsdb.db.First(&key, "prefix = ?", prefix); result.Error != nil {
return nil, result.Error
}

return &key, nil
}

// GetAPIKeyByID returns a ApiKey for a given id.
func (hsdb *HSDatabase) GetAPIKeyByID(id uint64) (*types.APIKey, error) {
hsdb.mu.RLock()
Expand Down Expand Up @@ -129,7 +138,7 @@ func (hsdb *HSDatabase) ValidateAPIKey(keyStr string) (bool, error) {
return false, ErrAPIKeyFailedToParse
}

key, err := hsdb.GetAPIKey(prefix)
key, err := hsdb.getAPIKey(prefix)
if err != nil {
return false, fmt.Errorf("failed to validate api key: %w", err)
}
Expand Down

0 comments on commit 670eb81

Please sign in to comment.