fix: replace blocking time.sleep with asyncio.sleep in async context (closes #125)#149
Open
geored wants to merge 2 commits into
Open
fix: replace blocking time.sleep with asyncio.sleep in async context (closes #125)#149geored wants to merge 2 commits into
geored wants to merge 2 commits into
Conversation
…loses #125) time.sleep(2) in _setup_port_forward blocks the entire asyncio event loop, freezing all concurrent MCP tool requests for 2 seconds. Replaced with await asyncio.sleep(2) which yields control back to the event loop. Also removed unused `import time` (only usage was this sleep call) and added explanatory comment for future maintainers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
time.sleep(2)in_setup_port_forward(line 520) is a synchronous C-level blocking call inside anasync deffunction. It freezes the entire asyncio event loop for 2 seconds, stalling all concurrent MCP tool requests during local development port-forwarding.Fix
Approach 2 (Defensive) — selected from 3 simulated approaches:
time.sleep(2)withawait asyncio.sleep(2)— yields control to the event loop during the waitimport asyncio(was not previously imported)import time(verified: only usage in file was this sleep call)Why This Approach
import timeand no documentationsubprocess.Popentoasyncio.create_subprocess_execbreaksstop_port_forward(sync method calling.wait(timeout=5)) and the type annotation at line 93Investigation Trace
import timeat line 19,asyncioNOT importedtime.sleep(2)at line 520 insideasync def _setup_port_forwardtime.usages — only one (line 520). Lines 1652/1660/1667 usedatetime, nottimeimport timeis safesubprocessimport must stay (15 usages across the file)Closes #125