Repository: yt-dlp
Issue: using check_formats causes connection timeout on youtube
Labels: bug,cant-reproduce,external issue,site:youtube

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Singapore

### Provide a description that is worded well enough to be understood

Using ytdlp via python API. If i set check_formats to true, all youtube URLs attempt to download/extract info will timeout after 20 seconds. Turning it off immediately resolves it.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No VT), error utf-8 (No VT), screen utf-8 (No VT)
[debug] yt-dlp version stable@2023.11.16 from yt-dlp/yt-dlp [24f827875] (pip) API
[debug] params: {'outtmpl': 'TITLE-%(id)s.%(ext)s', 'restrictfilenames': True, 'nocheckcertificate': True, 'ignoreerrors': False, 'logtostderr': False, 'geo-bypass': True, 'quiet': True, 'no_warnings': True, 'default_search': 'auto', 'source_address': '0.0.0.0', 'windowsfilenames': True, 'overwrites': True, 'cachedir': False, 'age_limit': 100, 'noplaylist': True, 'live_from_start': True, 'no-video-multistreams': True, 'no-audio-multistreams': True, 'check_formats': True, 'verbose': True, 'fixup': 'detect_or_warn', 'extractor_args': {'youtube': {'skip': ['dash', 'hls']}}, 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.70 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.9.13 (CPython AMD64 64bit) - Windows-10-10.0.19041-SP0 (OpenSSL 1.1.1n  15 Mar 2022)
[debug] exe versions: ffmpeg N-112938-g12e25af7a8-20231210 (setts), ffprobe N-112938-g12e25af7a8-20231210
[debug] Optional libraries: Cryptodome-3.17, brotli-1.1.0, certifi-2022.12.07, mutagen-1.46.0, requests-2.31.0, sqlite3-3.37.2, urllib3-2.1.0, websockets-11.0.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests
[debug] Loaded 1901 extractors
[youtube] Extracting URL: https://www.youtube.com/watch?v=q07EmkvztQM
[youtube] q07EmkvztQM: Downloading webpage
[youtube] q07EmkvztQM: Downloading ios player API JSON
[youtube] q07EmkvztQM: Downloading android player API JSON
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[info] Testing format 248
[debug] File locking is not supported. Proceeding without locking
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpkl0yniih.tmp
[info] Testing format 137
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmp2yhbodyi.tmp
[info] Testing format 399
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmp6xinkazn.tmp
[info] Testing format 247
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmp5_zg5g49.tmp
[info] Testing format 136
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmp_kc_dh8a.tmp
[info] Testing format 398
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpu7nji3wy.tmp
[info] Testing format 22
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpgz853453.tmp
[info] Testing format 244
[download] Got error: (<urllib3.connection.HTTPSConnection object at 0x00000120A2EE9F10>, 'Connection to rr5---sn-npobuxa-npoek.googlevideo.com timed out. (connect timeout=20.0)')
  File "C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\yt-dlp-gui.py", line 547, in <module>
    root.mainloop()
  File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1429, in mainloop
    self.tk.mainloop(n)
  File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\yt-dlp-gui.py", line 536, in <lambda>
    download_info_button = Button(buttons_frame, text='Customize Downloads', command=lambda: handle_download_info(url_input.get(), path_input.get()))
  File "C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\yt-dlp-gui.py", line 382, in handle_download_info
    info = extract_info(url, ydl_opts)
  File "C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\yt-dlp-gui.py", line 117, in extract_info
    info = ydl.extract_info(url, download=False)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1556, in extract_info
    return self.__extract_info(url, self.get_info_extractor(key), download, extra_info, process)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1567, in wrapper
    return func(self, *args, **kwargs)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1723, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1782, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 2820, in process_video_result
    if not formats or formats[0] is not info_dict:
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\utils\_utils.py", line 2188, in __getitem__
    self._exhaust()
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\utils\_utils.py", line 2160, in _exhaust
    self._cache.extend(self._iterable)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 2107, in _check_formats
    success, _ = self.dl(temp_file.name, f, test=True)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 3109, in dl
    return fd.download(name, new_info, subtitle)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\downloader\common.py", line 455, in download
    ret = self.real_download(filename, info_dict)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\downloader\http.py", line 362, in real_download
    for retry in RetryManager(self.params.get('retries'), self.report_retry):
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\utils\_utils.py", line 5114, in __iter__
    self.error_callback(self.error, self.attempt, self.retries)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\downloader\common.py", line 401, in report_retry
    RetryManager.report_retry(
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\utils\_utils.py", line 5121, in report_retry
    return error(f'{e}. Giving up after {count - 1} retries') if count > 1 else error(str(e))
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\downloader\common.py", line 404, in <lambda>
    error=IDENTITY if not fatal else lambda e: self.report_error(f'\r[download] Got error: {e}'),
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1045, in report_error
    self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)
  File "C:\Program Files\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 973, in trouble
    tb_data = traceback.format_list(traceback.extract_stack())

[info] Unable to download format 244. Skipping...
[info] Testing format 135
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpftztfbg2.tmp
[info] Testing format 397
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpb9nd_prn.tmp
[info] Testing format 243
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpvzwjz2ef.tmp
[info] Testing format 18
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpwkd75uhl.tmp
[info] Testing format 134
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpwcgdnrca.tmp
[info] Testing format 396
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmp8ghx8o8e.tmp
[info] Testing format 242
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmph81j9bb1.tmp
[info] Testing format 133
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpsjybp63a.tmp
[info] Testing format 395
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpvkx0trod.tmp
[info] Testing format 278
[download]   0.6% of    1.63MiB at    4.88MiB/s ETA 00:00  [download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpx_n124e5.tmp
[info] Testing format 160
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpi2a8lh8b.tmp
[info] Testing format 394
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpfzr7yntl.tmp
[info] Testing format 598
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmprtjijppw.tmp
[info] Testing format 597
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpmfnp1s4g.tmp
[info] Testing format 17
[download] Destination: C:\Users\alien\Documents\PyCharm-Projects\ytdlp-gui\tmpz_8e25w9.tmp
[info] Testing format 251

Process finished with exit code -1
```