diff --git a/requestmanager/requestmanager.go b/requestmanager/requestmanager.go index 4453e914..55b03ade 100644 --- a/requestmanager/requestmanager.go +++ b/requestmanager/requestmanager.go @@ -382,8 +382,8 @@ func (crm *cancelRequestMessage) handle(rm *RequestManager) { } func (prm *processResponseMessage) handle(rm *RequestManager) { - filteredResponses := rm.filterResponsesForPeer(prm.responses, prm.p) - filteredResponses = rm.processExtensions(filteredResponses, prm.p) + filteredResponses := rm.processExtensions(prm.responses, prm.p) + filteredResponses = rm.filterResponsesForPeer(filteredResponses, prm.p) rm.updateLastResponses(filteredResponses) responseMetadata := metadataForResponses(filteredResponses) rm.asyncLoader.ProcessResponse(responseMetadata, prm.blks) @@ -426,7 +426,10 @@ func (rm *RequestManager) processExtensionsForResponse(p peer.ID, response gsmsg rm.peerHandler.SendRequest(p, updateRequest) } if result.Err != nil { - requestStatus := rm.inProgressRequestStatuses[response.RequestID()] + requestStatus, ok := rm.inProgressRequestStatuses[response.RequestID()] + if !ok { + return false + } responseError := rm.generateResponseErrorFromStatus(graphsync.RequestFailedUnknown) select { case requestStatus.networkError <- responseError: diff --git a/requestmanager/requestmanager_test.go b/requestmanager/requestmanager_test.go index 471e67ab..61f47561 100644 --- a/requestmanager/requestmanager_test.go +++ b/requestmanager/requestmanager_test.go @@ -293,6 +293,10 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) { defer cancel() peers := testutil.GeneratePeers(1) + called := make(chan struct{}) + td.responseHooks.Register(func(p peer.ID, response graphsync.ResponseData, hookActions graphsync.IncomingResponseHookActions) { + close(called) + }) returnedResponseChan, returnedErrorChan := td.requestManager.SendRequest(requestCtx, peers[0], td.blockChain.TipLink, td.blockChain.Selector()) rr := readNNetworkRequests(requestCtx, t, td.requestRecordChan, 1)[0] @@ -310,6 +314,7 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) { td.fal.VerifyNoRemainingData(t, rr.gsr.ID()) testutil.VerifyEmptyErrors(ctx, t, returnedErrorChan) + testutil.AssertDoesReceive(requestCtx, t, called, "response hooks called for response") } func TestRequestReturnsMissingBlocks(t *testing.T) {