diff --git a/x/sync/manager.go b/x/sync/manager.go index ddcdc1637088..aad214a820f6 100644 --- a/x/sync/manager.go +++ b/x/sync/manager.go @@ -370,14 +370,14 @@ func (m *Manager) requestChangeProof(ctx context.Context, work *workItem) { } onResponse := func(ctx context.Context, _ ids.NodeID, responseBytes []byte, err error) { - defer m.finishWorkItem() - if err := m.handleChangeProofResponse(ctx, targetRootID, work, request, responseBytes, err); err != nil { // TODO log responses m.config.Log.Debug("dropping response", zap.Error(err), zap.Stringer("request", request)) m.retryWork(work) return } + + m.finishWorkItem() } if err := m.sendRequest(ctx, m.config.ChangeProofClient, requestBytes, onResponse); err != nil { @@ -428,14 +428,14 @@ func (m *Manager) requestRangeProof(ctx context.Context, work *workItem) { } onResponse := func(ctx context.Context, _ ids.NodeID, responseBytes []byte, appErr error) { - defer m.finishWorkItem() - if err := m.handleRangeProofResponse(ctx, targetRootID, work, request, responseBytes, appErr); err != nil { // TODO log responses m.config.Log.Debug("dropping response", zap.Error(err), zap.Stringer("request", request)) m.retryWork(work) return } + + m.finishWorkItem() } if err := m.sendRequest(ctx, m.config.RangeProofClient, requestBytes, onResponse); err != nil { @@ -467,6 +467,7 @@ func (m *Manager) retryWork(work *workItem) { m.workLock.Lock() m.unprocessedWork.Insert(work) + m.processingWorkItems-- m.workLock.Unlock() m.unprocessedWorkCond.Signal() }