Problem/Motivation
In issue 3613098, failures on import were surfaced to the user. This issue will address why the failures are happening in the first place.
Steps to reproduce
- Check out bibcite_crossref from the issue 3613098 merge request
- Import 12-20 references using a text file and bibcite_import
- Note the number of imported items reported after, and if less than the amount in the file, the error messages presented (likely 429 or 503 Too Many Requests).
Proposed resolution
Stay under Crossref’s published rate limits to avoid “Too Many Requests” error.
If no email is provided in the module config, then stay under 5 requests per second. If an email is provided and passed along to the request, then stay within 10 requests per second.
Remaining tasks
Code, test, have reviewed.
User interface changes
NA.
API changes
NA.
Data model changes
NA.
Issue fork bibcite_crossref-3613388
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
byronveale commentedOpened Merge Request, the 429 came from CrossrefClient::request() firing DOI lookups back-to-back with no rate limiting. This update, authored with assistance from Claude Opus 4.8, makes the client respect Crossref's REST API limits with:
The polite-pool mailto (which raises Crossref's limits) was already sent and is preserved.
Verified via a Guzzle MockHandler harness: retry-after-429 succeeds, sequential requests are correctly spaced (1.51s for 4 requests at 2/s), and persistent 429s throw after 5 attempts. php -l and phpcs (Drupal, DrupalPractice) are clean; the existing kernel test passes.
Note: fetching still happens synchronously during form validation, so throttling adds wall-clock time (small per request). For very large DOI lists, moving the fetch into the import batch would be the next structural improvement.
Comment #4
byronveale commentedForgot to note, this depends on a commit from the issue #3613098 Merge Request, so I made the current Merge Request dependent on that one.
Comment #5
bkosborneI found that Crossref publishes their rate limits, I think the logic here should be simplified to follow the published limits.
If no email is provided in the module config, then ensure we stay under 5 requests per second. If an email is provided and passed along to the request, then stay within 10 requests per second.
Then we don't need to worry about retry logic.
Comment #6
byronveale commentedAs per @bkosborne’s comment, simplifying this by staying under Crossref’s published rate limits.
Comment #7
bkosborneLooks good now. I tested with 50 entries in a file and didn't get any rate limit errors.
I did notice a possible issue which the way this is all set up. The import process uses Drupal's batch API and the batches are chunked so it imports 50 entities per operation. The issue we have is that decoding the DOI numbers is not part of that batch process, it happens before that. So if the user tries importing 500 items from one DOI file, it will take a minimum of 100 seconds just to decode all the DOIs because of the rate limiting. That's 100 seconds the form submission will be "pending" by the browser. It's of course half of that if the user provides an email since we can double the rate limit. But still.
In any case, that again can be resolved in some follow up, probably in a refactor of how the Bibcite Import module works to make the decoding process part of the batch operations, too.
Comment #9
byronveale commentedThanks @bkosborne. Opened new MR to get 3613098-report-import-errors commit in here.
Comment #11
byronveale commented