audiobookshelf icon indicating copy to clipboard operation
audiobookshelf copied to clipboard

[Bug]: "Match All Authors" with a big library will hit rate limits on Audible API and start getting 429s

Open FreedomBen opened this issue 2 years ago • 7 comments

Describe the issue

Expected behaviour Ideally the requests would be queued server-side to throttle them to avoid exceeding the rate limit threshold

Actual behaviour All lookups start to fail with 429s from Audible API. If your library is big enough, you may even get an IP ban

Steps to reproduce the issue

  1. Load hundreds of books from different authors into a library
  2. Visit the "authors" page
  3. Click "Match All Authors"
  4. Observe backend 429 errors from Audible API after several dozen lookups

Audiobookshelf version

v2.2.4. I can update and re-test in a little while but for the next week or so I need it to be perfectly stable as I'm traveling

How are you running audiobookshelf?

Docker

FreedomBen avatar Mar 01 '23 18:03 FreedomBen

Would a client-side fix in client/components/app/BookShelfToolbar.vue method matchAllAuthors() to add a small delay between POST requests be a reasonable (and acceptable for a PR) place to implement this?

Given that the endpoint is currently synchronous, it seems like a much bigger (and contract breaking) effort to turn it async and update the client accordingly, but I'm quite unfamiliar with this codebase so maybe there's something with the web socket that could be done without too much effort.

FreedomBen avatar Mar 01 '23 18:03 FreedomBen

Yeah I think a client-side fix is best here for the reason you pointed out. PR would be great.

We can do it server side with web socket events but probably more effort then it is worth at this stage. We're working on a new model to handle long running tasks so in the future we could make a match all authors route.

advplyr avatar Mar 01 '23 18:03 advplyr

One issue that just occurred to me is if the user navigates while the loop is running

advplyr avatar Mar 01 '23 18:03 advplyr

Perhaps a second button "Search Missing Authors". To lower the search volume.

sebclark avatar Mar 06 '23 15:03 sebclark

To lower the api calls further, maybe implement a maintenance task to search only the newly added authors, for e.g after a library scan, queue an author's update scan if new authors were added.

It will be high volume for the initial scan, but only searching for authors that have been added recently, probably after the last update, should only be queried, and also only authors not previously match in case they got an update. Similar to scan and force re-scan feature separation in case of library.

And I do not know how the code structure is right now, but shouldn't this make more sense as a server-side feature instead of client side? I mean server is responsible for maintaining the db of books, scanning and updating, why not authors too, just send an update call to server and let it handle. For larger libraries, you have to keep the tab open, also it uses a lot of resources, not to mention all the notifications of foo author found, bar author not found freezing up my system briefly every now and then.

Dr-Blank avatar Mar 19 '23 09:03 Dr-Blank

Any news on this? My library is pretty large so doing a rescan is already pretty impossible.

TheSylus avatar May 01 '23 19:05 TheSylus

Describe the issue

In some of my AudioBookShelf library, I have hundreds of authors. When I attempt to do an author match using Authors → Match All Authors, I get a match on some authors, but errors on others, including well-known authors. A rescan results in some of those missed authors being matched up. When I review the servers logs, I see the following:

2024-05-05 12:44:57.626 - INFO - [Audnexus] Searching for author "https://api.audnex.us/authors/B004AIN4W4?region=us"
2024-05-05 12:44:57.705 - ERROR - [Audnexus] Author request failed for B004AIN4W4 AxiosError: Request failed with status code 429
2024-05-05 12:44:57.730 - INFO - [Audnexus] Searching for author "https://api.audnex.us/authors?name=David+Javerbaum&region=us"
2024-05-05 12:44:57.821 - ERROR - [Audnexus] Author ASIN request failed for David Javerbaum AxiosError: Request failed with status code 429
2024-05-05 12:44:58.060 - DEBUG - [Audnexus] Looking up author by name Day Keene
2024-05-05 12:44:58.061 - INFO - [Audnexus] Searching for author "https://api.audnex.us/authors?name=Day+Keene&region=us"
2024-05-05 12:44:58.133 - ERROR - [Audnexus] Author ASIN request failed for Day Keene AxiosError: Request failed with status code 429

This tells me that AudioBookShelf is sending too many requests to api.audnex.us within a short period of time and needs to slow down and be rate limited to maybe one request every .25 to .5 seconds. Having author's being matched up is not a time-critical function, and waiting several minutes for the matching to complete should not be an unexpected condition. It may warrant a warning message when the administrator clicks on the Match All Authors that it may take some time to complete.

Screenshot from logs screen: image

Steps to reproduce the issue

  1. Go to a library with large number of authors
  2. Go to Authors
  3. Click on March All Authors
  4. Wait until red error messages appear.
  5. Go to Settings → Logs
  6. Filter for Warn-level messages

Audiobookshelf version

2.9.0

How are you running audiobookshelf?

Docker

ZLoth avatar May 05 '24 20:05 ZLoth

Thank you. Looking forward to the release! @advplyr

ZLoth avatar Jun 09 '24 20:06 ZLoth

Fixed in v2.11.0

advplyr avatar Jul 09 '24 20:07 advplyr

Thank you!

ZLoth avatar Jul 21 '24 23:07 ZLoth