@@ -133,14 +133,19 @@ func (s *normalizeState) removeLoops(ctx context.Context) {
133133 }
134134 }
135135
136- visited := map [digest.Digest ]struct {}{}
136+ globalVisited := map [digest.Digest ]struct {}{}
137137
138138 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 )
140145 }
141146}
142147
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 {} ) {
144149 it , ok := s .byKey [d ]
145150 if ! ok {
146151 return
@@ -149,7 +154,13 @@ func (s *normalizeState) checkLoops(ctx context.Context, d digest.Digest, visite
149154 if ! ok {
150155 return
151156 }
157+
158+ if _ , ok := globalVisited [d ]; ok {
159+ return
160+ }
161+
152162 visited [d ] = struct {}{}
163+ globalVisited [d ] = struct {}{}
153164 defer func () {
154165 delete (visited , d )
155166 }()
@@ -166,7 +177,7 @@ func (s *normalizeState) checkLoops(ctx context.Context, d digest.Digest, visite
166177 }
167178 delete (links [l ], id )
168179 } else {
169- s .checkLoops (ctx , id , visited )
180+ s .checkLoops (ctx , id , visited , globalVisited )
170181 }
171182 }
172183 }
0 commit comments