Fix context cancellation errors when fetching feature annotations
Issue Description
The GraphQL server is reporting context cancellation errors when attempting to fetch feature annotations for PubMed IDs related to gene DDB_G0267444.
Error Logs
{"level":"error","msg":"error fetching feature annotations for pubmed ID 21109012 (related to gene DDB_G0267444): rpc error: code = Canceled desc = context canceled","time":"02/May/2025:14:54:21"}
{"level":"error","msg":"failed fetching details for pub 21109012: error fetching feature annotations for pubmed ID 21109012 (related to gene DDB_G0267444): rpc error: code = Canceled desc = context canceled","time":"02/May/2025:14:54:21"}
{"level":"error","msg":"error fetching feature annotations for pubmed ID 20820770 (related to gene DDB_G0267444): rpc error: code = Canceled desc = context canceled","time":"02/May/2025:14:54:21"}
{"level":"error","msg":"failed fetching details for pub 20820770: error fetching feature annotations for pubmed ID 20820770 (related to gene DDB_G0267444): rpc error: code = Canceled desc = context canceled","time":"02/May/2025:14:54:21"}
Root Cause
The error occurs in the fetchPublicationDetails function in internal/graphql/resolver/publication.go when calling ListFeatureAnnotationsByPubmedId. The context is being canceled before the feature annotation request completes, either due to:
- A timeout in the feature annotation gRPC service
- Error propagation in the concurrent processing model - when one goroutine fails, it's canceling the context for all other requests
Potential Solutions
-
Add more robust error handling and prevent context cancellation from propagating across unrelated requests:
- Modify
fetchPublicationAsync to continue processing other publications when one fails
- Consider using separate contexts for each publication request
-
Implement retry logic with backoff for transient failures:
- Add a retry mechanism for gRPC calls with
Canceled error codes
- Use an exponential backoff strategy to avoid overwhelming the service
-
Increase timeout values if needed:
- Review and possibly extend timeout settings for the feature annotation client
-
Add detailed logging and metrics:
- Track response times for feature annotation requests
- Log timing information to identify potential bottlenecks
Affected Code
The issue is in internal/graphql/resolver/publication.go, specifically in the fetchPublicationDetails and fetchPublicationAsync functions.
Fix context cancellation errors when fetching feature annotations
Issue Description
The GraphQL server is reporting context cancellation errors when attempting to fetch feature annotations for PubMed IDs related to gene DDB_G0267444.
Error Logs
Root Cause
The error occurs in the
fetchPublicationDetailsfunction ininternal/graphql/resolver/publication.gowhen callingListFeatureAnnotationsByPubmedId. The context is being canceled before the feature annotation request completes, either due to:Potential Solutions
Add more robust error handling and prevent context cancellation from propagating across unrelated requests:
fetchPublicationAsyncto continue processing other publications when one failsImplement retry logic with backoff for transient failures:
Cancelederror codesIncrease timeout values if needed:
Add detailed logging and metrics:
Affected Code
The issue is in
internal/graphql/resolver/publication.go, specifically in thefetchPublicationDetailsandfetchPublicationAsyncfunctions.