Skip to content

Commit

Permalink
Fix so that resolve timeout does not cancel mirroring attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed May 16, 2024
1 parent 0a90881 commit f79104c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#460](https://github.com/spegel-org/spegel/pull/460) Fix environment variable for http-bootstrap-addr flag.
- [#471](https://github.com/spegel-org/spegel/pull/471) Fix handler key in request logging.
- [#491](https://github.com/spegel-org/spegel/pull/491) Fix so that resolve timeout does not cancel mirroring attempts.

### Security

Expand Down
3 changes: 1 addition & 2 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ func (r *Registry) handleMirror(rw mux.ResponseWriter, req *http.Request, ref re
mirrorAttempts := 0
for {
select {
// TODO: Refactor context cancel and mirror channel closing
case <-resolveCtx.Done():
case <-req.Context().Done():
// Request has been closed by server or client. No use continuing.
rw.WriteError(http.StatusNotFound, fmt.Errorf("mirroring for image component %s has been cancelled: %w", key, resolveCtx.Err()))
return
Expand Down
3 changes: 2 additions & 1 deletion pkg/routing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func (m *MockRouter) Ready() (bool, error) {
func (m *MockRouter) Resolve(ctx context.Context, key string, allowSelf bool, count int) (<-chan netip.AddrPort, error) {
peerCh := make(chan netip.AddrPort, count)
peers, ok := m.resolver[key]
// Not found will look forever until timeout.
// If not peers exist close the channel to stop any consumer.
if !ok {
close(peerCh)
return peerCh, nil
}
go func() {
Expand Down

0 comments on commit f79104c

Please sign in to comment.