Repository: beetbox/beets

Issue:
importing takes a very long time with discogs plugin enabled
### Problem
Whenever I want to import something in my library and I have Discogs enabled as a source, import operation can hang for various minutes while attempting to retrieve Discogs information.

Here is an example with discogs enabled
```
[user@host complete]$ time beet -vvv import -t OLIVIER_MESSIAEN_-_turangalila_symphonie\{orchestre_de_la_bastille+chung+loriod+loriod\}-DGG-SCD/
user configuration: /home/user/.config/beets/config.yaml
data directory: /home/user/.config/beets
plugin paths: 
Sending event: pluginload
inline: adding item field multidisc
artresizer: method is (2, (7, 1, 0), False)
library database: /home/user/.config/beets/beets.db
library directory: /home/user/Music
Sending event: library_opened
Sending event: import_begin
Sending event: import_task_created
Sending event: import_task_start
Looking up: /home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD
Tagging OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
No album ID found.
Search terms: OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
Album might be VA: False
Searching for MusicBrainz releases with: {'release': 'turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-dgg-scd', 'artist': 'olivier messiaen', 'tracks': '10'}
Requesting MusicBrainz release 1e24900c-e196-4e15-bba8-e9ada575a6b1
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Hans Rosbaud - Turangalîla - Symphonie (1e24900c-e196-4e15-bba8-e9ada575a6b1)
Computing track assignment...
...done.
Success. Distance: 0.55
Requesting MusicBrainz release 682c51b6-8468-476c-a739-5f1f6a3e00f5
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Berliner Philharmoniker, Kent Nagano, Pierre‐Laurent Aimard, Dominique Kim - Turangalîla-Symphonie (682c51b6-8468-476c-a739-5f1f6a3e00f5)
Computing track assignment...
...done.
Success. Distance: 0.56
Requesting MusicBrainz release 791ebf82-1757-47df-88ec-10bd7e81402f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; London Symphony Orchestra, Michel Béroff, Jeanne Loriod, André Previn - Turangalîla-symphonie (791ebf82-1757-47df-88ec-10bd7e81402f)
Computing track assignment...
...done.
Success. Distance: 0.57
Requesting MusicBrainz release 3e70ca3c-f448-4766-a029-d4f5644b5184
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Koninklijk Concertgebouworkest, Riccardo Chailly, Jean‐Yves Thibaudet, 原田節 - Turangalîla-Symphonie (3e70ca3c-f448-4766-a029-d4f5644b5184)
Computing track assignment...
...done.
Success. Distance: 0.60
Requesting MusicBrainz release 7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Jean‐Yves Thibaudet, 原田節, Koninklijk Concertgebouworkest, Riccardo Chailly - Turangalîla‐Symphonie (7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f)
Computing track assignment...
...done.
Success. Distance: 0.60
Evaluating 5 candidates.

/home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD (10 items)
Sending event: import_task_before_choice
Sending event: before_choose_candidate
Finding tags for album "OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD".
Candidates:
1. Olivier Messiaen; Hans Rosbaud - Turangalîla - Symphonie (45.2%) (tracks, album, artist) (CD, 1992, DE, WERGO, 286 401-2)
2. Olivier Messiaen; Berliner Philharmoniker, Kent Nagano, Pierre‐Laurent Aimard, Dominique Kim - Turangalîla-Symphonie (44.1%) (tracks, artist, album) (CD, 2001, DE, TELDEC, 8573-82043-2)
3. Olivier Messiaen; London Symphony Orchestra, Michel Béroff, Jeanne Loriod, André Previn - Turangalîla-symphonie (43.1%) (tracks, artist, album) (DVD-Audio, 2001, EMI Classics)
4. Olivier Messiaen; Koninklijk Concertgebouworkest, Riccardo Chailly, Jean‐Yves Thibaudet, 原田節 - Turangalîla-Symphonie (40.4%) (tracks, artist, album) (Hybrid SACD, 2003, XW, Decca Records, 470 627-2 DSA)
5. Olivier Messiaen; Jean‐Yves Thibaudet, 原田節, Koninklijk Concertgebouworkest, Riccardo Chailly - Turangalîla‐Symphonie (40.4%) (tracks, artist, album) (CD, 1993, XW, Decca Records, 436 626-2)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? s
Sending event: import_task_choice
Sending event: import
subsonicupdate: URL is http://192.168.1.215:4040/rest/startScan
subsonicupdate: auth type is token
subsonicupdate: Updating Subsonic; scanning 22459 tracks
Sending event: cli_exit

real	4m30.236s
user	0m0.810s
sys	0m0.075s
```

Compared to the same import without discogs plugin enabled:

```
[user@host complete]$ time beet -vvv import -t OLIVIER_MESSIAEN_-_turangalila_symphonie\{orchestre_de_la_bastille+chung+loriod+loriod\}-DGG-SCD/
user configuration: /home/user/.config/beets/config.yaml
data directory: /home/user/.config/beets
plugin paths: 
Sending event: pluginload
inline: adding item field multidisc
artresizer: method is (2, (7, 1, 0), False)
library database: /home/user/.config/beets/beets.db
library directory: /home/user/Music
Sending event: library_opened
Sending event: import_begin
Sending event: import_task_created
Sending event: import_task_start
Looking up: /home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD
Tagging OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
No album ID found.
Search terms: OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
Album might be VA: False
Searching for MusicBrainz releases with: {'release': 'turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-dgg-scd', 'artist': 'olivier messiaen', 'tracks': '10'}
Requesting MusicBrainz release 1e24900c-e196-4e15-bba8-e9ada575a6b1
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Hans Rosbaud - Turangalîla - Symphonie (1e24900c-e196-4e15-bba8-e9ada575a6b1)
Computing track assignment...
...done.
Success. Distance: 0.55
Requesting MusicBrainz release 791ebf82-1757-47df-88ec-10bd7e81402f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; London Symphony Orchestra, Michel Béroff, Jeanne Loriod, André Previn - Turangalîla-symphonie (791ebf82-1757-47df-88ec-10bd7e81402f)
Computing track assignment...
...done.
Success. Distance: 0.57
Requesting MusicBrainz release 682c51b6-8468-476c-a739-5f1f6a3e00f5
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Berliner Philharmoniker, Kent Nagano, Pierre‐Laurent Aimard, Dominique Kim - Turangalîla-Symphonie (682c51b6-8468-476c-a739-5f1f6a3e00f5)
Computing track assignment...
...done.
Success. Distance: 0.56
Requesting MusicBrainz release 7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Jean‐Yves Thibaudet, 原田節, Koninklijk Concertgebouworkest, Riccardo Chailly - Turangalîla‐Symphonie (7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f)
Computing track assignment...
...done.
Success. Distance: 0.60
Requesting MusicBrainz release 3e70ca3c-f448-4766-a029-d4f5644b5184
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Koninklijk Concertgebouworkest, Riccardo Chailly, Jean‐Yves Thibaudet, 原田節 - Turangalîla-Symphonie (3e70ca3c-f448-4766-a029-d4f5644b5184)
Computing track assignment...
...done.
Success. Distance: 0.60
Evaluating 5 candidates.

/home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD (10 items)
Sending event: import_task_before_choice
Sending event: before_choose_candidate
Finding tags for album "OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD".
Candidates:
1. Olivier Messiaen; Hans Rosbaud - Turangalîla - Symphonie (45.2%) (tracks, album, artist) (CD, 1992, DE, WERGO, 286 401-2)
2. Olivier Messiaen; Berliner Philharmoniker, Kent Nagano, Pierre‐Laurent Aimard, Dominique Kim - Turangalîla-Symphonie (44.1%) (tracks, artist, album) (CD, 2001, DE, TELDEC, 8573-82043-2)
3. Olivier Messiaen; London Symphony Orchestra, Michel Béroff, Jeanne Loriod, André Previn - Turangalîla-symphonie (43.1%) (tracks, artist, album) (DVD-Audio, 2001, EMI Classics)
4. Olivier Messiaen; Jean‐Yves Thibaudet, 原田節, Koninklijk Concertgebouworkest, Riccardo Chailly - Turangalîla‐Symphonie (40.4%) (tracks, artist, album) (CD, 1993, XW, Decca Records, 436 626-2)
5. Olivier Messiaen; Koninklijk Concertgebouworkest, Riccardo Chailly, Jean‐Yves Thibaudet, 原田節 - Turangalîla-Symphonie (40.4%) (tracks, artist, album) (Hybrid SACD, 2003, XW, Decca Records, 470 627-2 DSA)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? s
Sending event: import_task_choice
Sending event: import
subsonicupdate: URL is http://192.168.1.215:4040/rest/startScan
subsonicupdate: auth type is token
subsonicupdate: Updating Subsonic; scanning 22459 tracks
Sending event: cli_exit

real	0m9.208s
user	0m0.781s
sys	0m0.043s
```

### Setup

* OS: Arch Linux 5.14.12-arch1-1
* Python version: Python 3.9.7
* beets version: beets version 1.5.1
* Turning off plugins made problem go away (yes/no): turning off discogs plugin clearly makes the problem go away

My configuration (output of `beet config`) is: 

This issue is reproducible on any instance and I don't believe it being tied to my specific configuration file, the relevant discogs section just contains the token
```yaml
discogs:
    user_token: ######################
```



Discussion:
Additionally to the issue with the high waiting time, I am also noticing how there are no results obtained from `discogs` since both imports are just evaluating 5 candidates from `musicbrainz`; this is however false as we can see the master is present on the site with multiple releases attached: https://www.discogs.com/master/378710-Messiaen-Yvonne-Loriod-Jeanne-Loriod-Orchestre-De-LOp%C3%A9ra-Bastille-Myung-Whun-Chung-Turangal%C3%AEla-Sym

My first question therefore is: what is the program doing for 4+ minutes instead of scraping `discogs` for results? there is no logging on console so I don't really know...

Second question: what happens when I use `--search-id `on `beet import` to pass a specific release ID from `discogs`? Ideally this should be much faster since we don't have to scrape anything but just pull the specific release information, however the waiting time just grows exponentially
```
[user@host complete]$ time beet -vvv import OLIVIER_MESSIAEN_-_turangalila_symphonie\{orchestre_de_la_bastille+chung+loriod+loriod\}-DGG-SCD/ --search-id 5422673
user configuration: /home/user/.config/beets/config.yaml
data directory: /home/user/.config/beets
plugin paths: 
Sending event: pluginload
inline: adding item field multidisc
artresizer: method is (2, (7, 1, 0), False)
library database: /home/user/.config/beets/beets.db
library directory: /home/user/Music
Sending event: library_opened
Sending event: import_begin
Sending event: import_task_created
Sending event: import_task_start
Looking up: /home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD
Tagging OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
Searching for album ID: 5422673
Requesting MusicBrainz release 5422673
Invalid MBID (5422673).
discogs: Searching for release 5422673
discogs: Searching for master release 378710
Sending event: albuminfo_received
Candidate: Olivier Messiaen, Yvonne Loriod, Jeanne Loriod, Orchestre De L'Opéra Bastille, Myung-Whun Chung - Turangalîla-Symphonie (5422673)
Computing track assignment...
...done.
Success. Distance: 0.22
Evaluating 1 candidates.

/home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD (10 items)
Sending event: import_task_before_choice
Sending event: before_choose_candidate
Correcting tags from:
    OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
To:
    Olivier Messiaen, Yvonne Loriod, Jeanne Loriod, Orchestre De L'Opéra Bastille, Myung-Whun Chung - Turangalîla-Symphonie
URL:
    https://www.discogs.com/release/5422673-Messiaen-Yvonne-Loriod-Jeanne-Loriod-Orchestre-De-LOp%C3%A9ra-Bastille-Myung-Whun-Chung-Turangal%C3%AEla-Sym
(Similarity: 77.9%) (artist, album, source, tracks) (Discogs, CD, 2005, Germany, Deutsche Grammophon, 431 781-2)
CD: Turangalîla-Symphonie Pour Piano Principal Et Grand Orchestre
 * introduction-modere un peu vif                    -> I, Introduction: Modéré, Un Peu Vif (title)
 * chant d'amour 1-modere lourd                      -> II. Chant D'Amour 1: Modéré, Lourd (title)
 * turangalila 1-presque lent reveur                 -> III. Turangalîla 1: Presque Lent, Rêveur (title)
 * chant d'amour 2-bien modere                       -> IV. Chant D'Amour 2: Bien Modéré (title)
 * joie du sang des etoiles-vif passione avec joie   -> V. Joie Du Sang Des Étoiles: Vif, Passionné, Avec Joie (title)
 * jardin du sommeil d'amour-tres modere tres tendre -> VI. Jardin Du Sommeil D'Amour: Très Modéré, Très Tendre (title)
 * turangalila 2-un peu vif bien modere              -> VII. Turangalîla 2: Un Peu Vif - Bien Modéré (title)
 * developpement de l'amour-bien modere              -> VIII. Développement De L'Amour: Bien Modéré (title)
 * turangalila 3-bien modere                         -> IX. Turangalîla 3: Bien Modéré (title)
 * final-modere presque vif avec une grande joie     -> X. Final: Modéré, Presque Vif, Avec Une Grande Joie (title)
[A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates? s
Sending event: import_task_choice
Sending event: import
subsonicupdate: URL is http://192.168.1.215:4040/rest/startScan
subsonicupdate: auth type is token
subsonicupdate: Updating Subsonic; scanning 22459 tracks
Sending event: cli_exit

real	9m22.692s
user	0m0.500s
sys	0m0.073s
```
Hmm; is there any chance the Discogs search APIs are/were down or inaccessible? That seems like the simplest explanation for searching Discogs being slow and returning no results…
the discogs api itself is working fine (as in reachability) as it can be seen when passing `--search-id`

also I would expect any issue where the API is down or inaccessible to print some error message on console (if not from beets, from the library being used) but here nothing shows up at all

please let me know which other info you may need to triage this
Certainly, but what I meant to ask was whether the search API specifically, rather than the ID lookup API, might be down.

I can think of two ways to start trying to narrow this down:
- Watch the verbose logs to see exactly where the pause happens. Between which two events does it seem to wait for longest?
- Try monkeying with the plugin's code. Inserting a few `print` statements around the network communication calls might help narrow down what is taking so long.
> Certainly, but what I meant to ask was whether the search API specifically, rather than the ID lookup API, might be down.

When I use `--search-id` the total time taken is over 9 minutes (twice as much as searching), leaving out the search functionality I believe 4m 30s is still too much to download a single release, don't you agree?

> Watch the verbose logs to see exactly where the pause happens. Between which two events does it seem to wait for longest?

good point, from the command output it's not clear where the command hangs, it always happens after `Evaluating X candidates.`

will try adding some print statements to the plugin and see what else happens
well I guess it was rather easy to find the source of the problem, all I needed was to add a simple statement there

[discogs plugin](https://github.com/beetbox/beets/blob/master/beetsplug/discogs.py)
```
    def _time_to_next_request(self):
        seconds_between_requests = 60 / self.rate_limit_per_minute
        seconds_since_last_request = time.time() - self.last_request_timestamp
        seconds_to_wait = seconds_between_requests - seconds_since_last_request
        **self._log.debug('waiting {0} seconds', seconds_to_wait)**
        return seconds_to_wait
```

then I ran import again and...
```
[user@hostcomplete]$ beet -vvv import -t OLIVIER_MESSIAEN_-_turangalila_symphonie\{orchestre_de_la_bastille+chung+loriod+loriod\}-DGG-SCD/
user configuration: /home/user/.config/beets/config.yaml
data directory: /home/user/.config/beets
plugin paths:
Sending event: pluginload
inline: adding item field multidisc
artresizer: method is (2, (7, 1, 0), False)
library database: /home/user/.config/beets/beets.db
library directory: /home/user/Music
Sending event: library_opened
Sending event: import_begin
Sending event: import_task_created
Sending event: import_task_start
Looking up: /home/user/complete/OLIVIER_MESSIAEN_-_turangalila_symphonie{orchestre_de_la_bastille+chung+loriod+loriod}-DGG-SCD
Tagging OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
No album ID found.
Search terms: OLIVIER MESSIAEN - turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-DGG-SCD
Album might be VA: False
Searching for MusicBrainz releases with: {'release': 'turangalila symphonie{orchestre de la bastille+chung+loriod+loriod}-dgg-scd', 'artist': 'olivier messiaen', 'tracks': '10'}
Requesting MusicBrainz release 1e24900c-e196-4e15-bba8-e9ada575a6b1
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Hans Rosbaud - Turangalîla - Symphonie (1e24900c-e196-4e15-bba8-e9ada575a6b1)
Computing track assignment...
...done.
Success. Distance: 0.55
Requesting MusicBrainz release 791ebf82-1757-47df-88ec-10bd7e81402f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; London Symphony Orchestra, Michel Béroff, Jeanne Loriod, André Previn - Turangalîla-symphonie (791ebf82-1757-47df-88ec-10bd7e81402f)
Computing track assignment...
...done.
Success. Distance: 0.57
Requesting MusicBrainz release 682c51b6-8468-476c-a739-5f1f6a3e00f5
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Berliner Philharmoniker, Kent Nagano, Pierre‐Laurent Aimard, Dominique Kim - Turangalîla-Symphonie (682c51b6-8468-476c-a739-5f1f6a3e00f5)
Computing track assignment...
...done.
Success. Distance: 0.56
Requesting MusicBrainz release 7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Jean‐Yves Thibaudet, 原田節, Koninklijk Concertgebouworkest, Riccardo Chailly - Turangalîla‐Symphonie (7d75b8a3-7c4b-3af7-bb8f-3cf3d811995f)
Computing track assignment...
...done.
Success. Distance: 0.60
Requesting MusicBrainz release 3e70ca3c-f448-4766-a029-d4f5644b5184
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_track_extract
Sending event: mb_album_extract
Sending event: albuminfo_received
Candidate: Olivier Messiaen; Koninklijk Concertgebouworkest, Riccardo Chailly, Jean‐Yves Thibaudet, 原田節 - Turangalîla-Symphonie (3e70ca3c-f448-4766-a029-d4f5644b5184)
Computing track assignment...
...done.
Success. Distance: 0.60
**discogs: waiting -1634798140.986836 seconds**
```

my problem now is that I have not a clue of where to start to fix this, if someone could help/take care of this I would be extremely grateful.
also curious of how this was not caught by any test, unless clearly there is no test case for it :)
after further digging this has been introduced in PR https://github.com/beetbox/beets/pull/3138
As we are using [python3-discogs-client ](https://github.com/joalla/discogs_client) and the rate limiting function has been released as follows [Access remaining rate limit](https://github.com/joalla/discogs_client/discussions/21), we should review how we can leverage the rate limiting native function rather than a random wait between calls. Rate limiting enabled by default.

[Requests rate limiting](https://python3-discogs-client.readthedocs.io/en/latest/requests_rate_limit.html)

Looks like a simple fix to remove the rate limiting included in #3138
That's a good idea, @arogl!

Resolving patch:
diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py
--- a/beetsplug/discogs.py
+++ b/beetsplug/discogs.py
@@ -63,8 +63,6 @@ def __init__(self):
         self.config['user_token'].redact = True
         self.discogs_client = None
         self.register_listener('import_begin', self.setup)
-        self.rate_limit_per_minute = 25
-        self.last_request_timestamp = 0
 
     def setup(self, session=None):
         """Create the `discogs_client` field. Authenticate if necessary.
@@ -77,7 +75,6 @@ def setup(self, session=None):
         if user_token:
             # The rate limit for authenticated users goes up to 60
             # requests per minute.
-            self.rate_limit_per_minute = 60
             self.discogs_client = Client(USER_AGENT, user_token=user_token)
             return
 
@@ -95,26 +92,6 @@ def setup(self, session=None):
         self.discogs_client = Client(USER_AGENT, c_key, c_secret,
                                      token, secret)
 
-    def _time_to_next_request(self):
-        seconds_between_requests = 60 / self.rate_limit_per_minute
-        seconds_since_last_request = time.time() - self.last_request_timestamp
-        seconds_to_wait = seconds_between_requests - seconds_since_last_request
-        return seconds_to_wait
-
-    def request_start(self):
-        """wait for rate limit if needed
-        """
-        time_to_next_request = self._time_to_next_request()
-        if time_to_next_request > 0:
-            self._log.debug('hit rate limit, waiting for {0} seconds',
-                            time_to_next_request)
-            time.sleep(time_to_next_request)
-
-    def request_finished(self):
-        """update timestamp for rate limiting
-        """
-        self.last_request_timestamp = time.time()
-
     def reset_auth(self):
         """Delete token file & redo the auth steps.
         """
@@ -266,11 +243,9 @@ def get_albums(self, query):
         # can also negate an otherwise positive result.
         query = re.sub(r'(?i)\b(CD|disc)\s*\d+', '', query)
 
-        self.request_start()
         try:
             releases = self.discogs_client.search(query,
                                                   type='release').page(1)
-            self.request_finished()
 
         except CONNECTION_ERRORS:
             self._log.debug("Communication error while searching for {0!r}",
@@ -286,10 +261,8 @@ def get_master_year(self, master_id):
         self._log.debug('Searching for master release {0}', master_id)
         result = Master(self.discogs_client, {'id': master_id})
 
-        self.request_start()
         try:
             year = result.fetch('year')
-            self.request_finished()
             return year
         except DiscogsAPIError as e:
             if e.status_code != 404:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -127,7 +127,7 @@ def build_manpages():
         'embyupdate': ['requests'],
         'chroma': ['pyacoustid'],
         'gmusic': ['gmusicapi'],
-        'discogs': ['python3-discogs-client'],
+        'discogs': ['python3-discogs-client>=2.3.10'],
         'beatport': ['requests-oauthlib>=0.6.1'],
         'kodiupdate': ['requests'],
         'lastgenre': ['pylast'],


Test patch: