@@ -133,14 +133,19 @@ func (s *normalizeState) removeLoops(ctx context.Context) {
133
133
}
134
134
}
135
135
136
- visited := map [digest.Digest ]struct {}{}
136
+ globalVisited := map [digest.Digest ]struct {}{}
137
137
138
138
for _ , d := range roots {
139
- s .checkLoops (ctx , d , visited )
139
+ if _ , ok := globalVisited [d ]; ok {
140
+ continue
141
+ }
142
+
143
+ visited := map [digest.Digest ]struct {}{}
144
+ s .checkLoops (ctx , d , visited , globalVisited )
140
145
}
141
146
}
142
147
143
- func (s * normalizeState ) checkLoops (ctx context.Context , d digest.Digest , visited map [digest.Digest ]struct {}) {
148
+ func (s * normalizeState ) checkLoops (ctx context.Context , d digest.Digest , visited map [digest.Digest ]struct {}, globalVisited map [digest. Digest ] struct {} ) {
144
149
it , ok := s .byKey [d ]
145
150
if ! ok {
146
151
return
@@ -149,7 +154,13 @@ func (s *normalizeState) checkLoops(ctx context.Context, d digest.Digest, visite
149
154
if ! ok {
150
155
return
151
156
}
157
+
158
+ if _ , ok := globalVisited [d ]; ok {
159
+ return
160
+ }
161
+
152
162
visited [d ] = struct {}{}
163
+ globalVisited [d ] = struct {}{}
153
164
defer func () {
154
165
delete (visited , d )
155
166
}()
@@ -166,7 +177,7 @@ func (s *normalizeState) checkLoops(ctx context.Context, d digest.Digest, visite
166
177
}
167
178
delete (links [l ], id )
168
179
} else {
169
- s .checkLoops (ctx , id , visited )
180
+ s .checkLoops (ctx , id , visited , globalVisited )
170
181
}
171
182
}
172
183
}
0 commit comments