-
Notifications
You must be signed in to change notification settings - Fork 190
Added timeout for handling read and write operations #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added timeout for handling read and write operations #995
Conversation
|
Hi @parth-soni07 , thanks for the quick fixes. The code looks great now. You've resolved the duplicate receive issue and the EOF reading is now using the timeout version like it should. I also noticed you moved the The deadline handling is now working properly throughout the read and write operations, and the error messages are clear and helpful. This is good to merge. Nice work getting the deadline functionality working, this has been a TODO for a while. CC @seetadev and @pacrob |
Hey @paschal533 , thank you for your review! :) |
|
@parth-soni07 : Appreciate your efforts and contribution. Doing a detailed review. Will share feedback soon. Also, CCing @acul71 and @Jineshbansal, who were working on this feature earlier. Wish if you could resolve the merge conflicts. Once resolved, please ping me. I will re-run the CI/CD pipeline and share test results soon. |
|
Good work, @parth-soni07! This still needs a newsfragment and testing to verify things are working as expected and to prevent regression. |
|
@parth-soni07 Implement MplexStream read and write deadline timeout enforcement #987 |
| @@ -1,3 +1,4 @@ | |||
| import time | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use trio.current_time() instead of time.time().
time.time() returns wall-clock time, which can jump backward or forward if the system clock changes (e.g., due to NTP).
trio.current_time() is monotonic and stable, making it the safer choice for deadlines and timeouts in async code.
|
Hello @parth-soni07 , thanks, for this PR. SummaryPR #995 should be closed because:
Comparison
RecommendationClose PR #995 with a comment explaining:
Bottom line: PR #995 is a refactoring attempt that introduces bugs without clear benefits. The original issue is already fixed, so this PR is not needed. ################################### PR #995 Relevance Analysis: Should This PR Be Closed?Executive SummaryRecommendation: PR #995 should be CLOSED unless the author can provide clear justification for the refactoring and fix all critical bugs. Reasoning:
Comparison: PR #987 vs PR #995PR #987 (Merged 2025-10-19) - Current ImplementationApproach: TTL-based deadline enforcement
Code Example: read_deadline: int | None # TTL in seconds
def set_read_deadline(self, ttl: int) -> bool:
if not self._validate_ttl(ttl):
return False
self.read_deadline = ttl
return True
async def read(self, n: int | None = None) -> bytes:
return await self._with_timeout(
self.read_deadline, "Read", lambda: self._do_read(n)
)Status: ✅ Working, tested, merged PR #995 (Current) - Proposed ChangesApproach: Absolute timestamp-based deadline enforcement
Code Example: read_deadline: float | None # Absolute timestamp
def set_read_deadline(self, ttl: int) -> bool:
self.read_deadline = time.time() + ttl # No validation!
return True
async def read(self, n: int | None = None) -> bytes:
self._check_read_deadline() # Check before starting
# ... more deadline checks ...
return await self._with_timeout(
self.read_deadline, "Read", lambda: self._do_read(n)
# ❌ TYPE ERROR: read_deadline is float, _with_timeout expects int
)Status: ❌ Broken, has bugs, tests fail Key Differences
Potential Benefits of PR #995's Approach
Problems with PR #995Critical Issues
Test Failures10 tests fail because they expect TTL format:
Is PR #995 Still Relevant?Arguments for Keeping PR #995
Arguments for Closing PR #995
RecommendationOption 1: Close PR #995 (Recommended)Reason: PR #987 already fixed the issue. PR #995 is a refactoring attempt that:
Action: Close PR with comment explaining that:
Option 2: Request Major Changes (If Author Wants to Continue)Reason: If there's a valid reason for absolute timestamps, the PR needs significant work. Required Changes:
Likelihood of Success: Low - requires significant work and justification ConclusionPR #995 should be CLOSED because:
If the author believes absolute timestamps provide significant benefits, they should:
Current Status: PR #995 is not ready for merge and lacks clear justification for the refactoring. |
What was wrong?
Issue #723
How was it fixed?
Modified the read() and write() methods to actually check and enforce the deadlines.