|
|
b9462c |
From 6eadd954e5a02f2dcf93928484d42f86b6975618 Mon Sep 17 00:00:00 2001
|
|
|
b9462c |
From: TomSweeneyRedHat <tsweeney@redhat.com>
|
|
|
b9462c |
Date: Fri, 4 Oct 2019 15:44:20 -0400
|
|
|
b9462c |
Subject: [PATCH] Fix Docker search race/panic - BZ1732626 - 1.13.1
|
|
|
b9462c |
|
|
|
b9462c |
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
|
|
|
b9462c |
---
|
|
|
b9462c |
registry/service.go | 34 ++++++++++++++++++----------------
|
|
|
b9462c |
1 file changed, 18 insertions(+), 16 deletions(-)
|
|
|
b9462c |
|
|
|
b9462c |
diff --git a/registry/service.go b/registry/service.go
|
|
|
b9462c |
index f4b7d65d1dba..cc43987a6a9a 100644
|
|
|
b9462c |
--- a/registry/service.go
|
|
|
b9462c |
+++ b/registry/service.go
|
|
|
b9462c |
@@ -188,9 +188,9 @@ func getSearchResultsCmpFunc(withIndex bool) by {
|
|
|
b9462c |
return less
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
-func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[string]types.AuthConfig, userAgent string, headers map[string][]string, noIndex bool, outs *[]registrytypes.SearchResultExt) error {
|
|
|
b9462c |
+func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[string]types.AuthConfig, userAgent string, headers map[string][]string, noIndex bool, outs []registrytypes.SearchResultExt) ([]registrytypes.SearchResultExt, error) {
|
|
|
b9462c |
if err := validateNoScheme(term); err != nil {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
indexName, remoteName := splitReposSearchTerm(term, true)
|
|
|
b9462c |
@@ -201,13 +201,13 @@ func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[stri
|
|
|
b9462c |
s.mu.Unlock()
|
|
|
b9462c |
|
|
|
b9462c |
if err != nil {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
// *TODO: Search multiple indexes.
|
|
|
b9462c |
endpoint, err := NewV1Endpoint(index, userAgent, http.Header(headers))
|
|
|
b9462c |
if err != nil {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
ac := ResolveAuthConfig(authConfigs, index)
|
|
|
b9462c |
@@ -228,7 +228,7 @@ func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[stri
|
|
|
b9462c |
if fErr, ok := err.(fallbackError); ok {
|
|
|
b9462c |
logrus.Errorf("Cannot use identity token for search, v2 auth not supported: %v", fErr.err)
|
|
|
b9462c |
} else {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
} else if foundV2 {
|
|
|
b9462c |
// Copy non transport http client features
|
|
|
b9462c |
@@ -244,13 +244,13 @@ func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[stri
|
|
|
b9462c |
if client == nil {
|
|
|
b9462c |
client = endpoint.client
|
|
|
b9462c |
if err := authorizeClient(client, authConfig, endpoint); err != nil {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
r, err := NewSession(client, authConfig, endpoint)
|
|
|
b9462c |
if err != nil {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
var results *registrytypes.SearchResults
|
|
|
b9462c |
@@ -266,12 +266,12 @@ func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[stri
|
|
|
b9462c |
results, err = r.SearchRepositories(remoteName, limit)
|
|
|
b9462c |
}
|
|
|
b9462c |
if err != nil || results.NumResults < 1 {
|
|
|
b9462c |
- return err
|
|
|
b9462c |
+ return outs, err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
- newOuts := make([]registrytypes.SearchResultExt, len(*outs)+len(results.Results))
|
|
|
b9462c |
- for i := range *outs {
|
|
|
b9462c |
- newOuts[i] = (*outs)[i]
|
|
|
b9462c |
+ newOuts := make([]registrytypes.SearchResultExt, len(outs)+len(results.Results))
|
|
|
b9462c |
+ for i := range outs {
|
|
|
b9462c |
+ newOuts[i] = (outs)[i]
|
|
|
b9462c |
}
|
|
|
b9462c |
for i, result := range results.Results {
|
|
|
b9462c |
item := registrytypes.SearchResultExt{
|
|
|
b9462c |
@@ -289,10 +289,10 @@ func (s *DefaultService) searchTerm(term string, limit int, authConfigs map[stri
|
|
|
b9462c |
if newRegistryName != "" {
|
|
|
b9462c |
item.RegistryName, item.Name = newRegistryName, newName
|
|
|
b9462c |
}
|
|
|
b9462c |
- newOuts[len(*outs)+i] = item
|
|
|
b9462c |
+ newOuts[len(outs)+i] = item
|
|
|
b9462c |
}
|
|
|
b9462c |
- *outs = newOuts
|
|
|
b9462c |
- return nil
|
|
|
b9462c |
+ outs = newOuts
|
|
|
b9462c |
+ return outs, nil
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
// Duplicate entries may occur in result table when omitting index from output because
|
|
|
b9462c |
@@ -341,15 +341,17 @@ func removeSearchDuplicates(data []registrytypes.SearchResultExt) []registrytype
|
|
|
b9462c |
func (s *DefaultService) Search(ctx context.Context, term string, limit int, authConfigs map[string]types.AuthConfig, userAgent string, headers map[string][]string, noIndex bool) ([]registrytypes.SearchResultExt, error) {
|
|
|
b9462c |
results := []registrytypes.SearchResultExt{}
|
|
|
b9462c |
cmpFunc := getSearchResultsCmpFunc(!noIndex)
|
|
|
b9462c |
+ var err error
|
|
|
b9462c |
|
|
|
b9462c |
// helper for concurrent queries
|
|
|
b9462c |
searchRoutine := func(term string, c chan<- error) {
|
|
|
b9462c |
- err := s.searchTerm(term, limit, authConfigs, userAgent, headers, noIndex, &results)
|
|
|
b9462c |
+ results, err = s.searchTerm(term, limit, authConfigs, userAgent, headers, noIndex, results)
|
|
|
b9462c |
c <- err
|
|
|
b9462c |
}
|
|
|
b9462c |
|
|
|
b9462c |
if isReposSearchTermFullyQualified(term) {
|
|
|
b9462c |
- if err := s.searchTerm(term, limit, authConfigs, userAgent, headers, noIndex, &results); err != nil {
|
|
|
b9462c |
+ results, err = s.searchTerm(term, limit, authConfigs, userAgent, headers, noIndex, results)
|
|
|
b9462c |
+ if err != nil {
|
|
|
b9462c |
return nil, err
|
|
|
b9462c |
}
|
|
|
b9462c |
} else if len(DefaultRegistries) < 1 {
|