Skip to content

fix: run blocking chardet.detect in thread executor #1751#1760

Open
nitesh-77 wants to merge 1 commit intounclecode:mainfrom
nitesh-77:fix/async-chardet-block
Open

fix: run blocking chardet.detect in thread executor #1751#1760
nitesh-77 wants to merge 1 commit intounclecode:mainfrom
nitesh-77:fix/async-chardet-block

Conversation

@nitesh-77
Copy link

Fixes #1751
The Bug:
chardet.detect is CPU-bound and was blocking the main asyncio event loop in _handle_http, causing lags of 1+ seconds on large pages.
The Fix:
Wrapped the detection in asyncio.to_thread to offload it to a worker thread.
Verification:
Verified locally with a reproduction script; the event loop heartbeat remained active during detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: chardet.detect() blocks asyncio event loop in _handle_http

1 participant

Comments