Skip to content

Fix video_dl hanging silently (blocking event loop)#181

Merged
psykzz merged 1 commit into
mainfrom
fix/video-dl-blocking-event-loop
Jun 21, 2026
Merged

Fix video_dl hanging silently (blocking event loop)#181
psykzz merged 1 commit into
mainfrom
fix/video-dl-blocking-event-loop

Conversation

@psykzz

@psykzz psykzz commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

video_dl was showing a typing indicator but never responding. The root cause was synchronous blocking I/O running directly on the asyncio event loop.

Root cause

yt_dlp.YoutubeDL.extract_info() (both the size-probe pass and the actual download) and catboxpy's client.upload() are synchronous calls. Calling them inside an async function without offloading to a thread freezes the entire event loop — the typing indicator heartbeat can't fire, no reply is ever sent, and no error appears in logs.

Changes

  • Wrap the yt-dlp probe + download in asyncio.to_thread(_run_download) so the event loop stays free
  • Wrap catbox client.upload() in asyncio.to_thread(_do_upload) for the same reason
  • Add import asyncio (was missing)
  • Guard on_message's catbox/emoji paths against message.guild is None (DM context where the bot owner triggers a download — previously would raise AttributeError)

Testing

  • Python syntax validated: python -m py_compile video_dl/video_dl.py
  • Linting clean: flake8 video_dl/video_dl.py --select=E9,F63,F7,F82
  • Full end-to-end testing requires a live bot; blocking-call fix is mechanically straightforward

Risk

Low. Change is isolated to threading the I/O work off the event loop — no logic changes to download/upload behaviour. DM guard is defensive and was always a latent crash.

Closes #180

Synchronous yt_dlp.YoutubeDL calls (probe + download) and
catboxpy's client.upload() were blocking the asyncio event loop.
The typing indicator fired but nothing else could run — no download,
no reply, no log output.

Wraps both in asyncio.to_thread() via inner _run_download /
_do_upload helpers so the event loop stays free.

Also guards on_message catbox path against message.guild being None
(DM context), which would have raised AttributeError after a
successful download in a DM.

Closes #180
@psykzz psykzz added the bug Something isn't working label Jun 21, 2026
@psykzz psykzz merged commit 515e258 into main Jun 21, 2026
3 checks passed
@psykzz psykzz deleted the fix/video-dl-blocking-event-loop branch June 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: video_dl cog

1 participant