Skip to content

Validate lock timeout range before acquire restrictions - #9061

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-rlock-timeout-range-order
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-rlock-timeout-range-order

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow up on the range-precedence review of merged #9035: #9035 (comment).

Check whether a timeout fits signed nanoseconds before applying the nonblocking and negative-timeout restrictions. This makes out-of-range values and infinities raise OverflowError before those argument-combination errors, including reentrant RLock acquisition. The implementation adds five lines to the existing shared validator; the existing Python regression table gains focused range cases.

The signed conversion limit is distinct from the later platform maximum. In particular, Windows values outside its positive timeout maximum can still fit signed nanoseconds; negative values in that range must retain ValueError. The -1 sentinel, NaN handling, accepted timeout values, locking implementation and recursion accounting are unchanged.

Exact reference sources:

Scope and validation

This is a narrow review correction, not a rewrite of timeout conversion. The pre-existing comparison against the floored public TIMEOUT_MAX still rejects some fractional values that CPython accepts; that adjacent discrepancy is unchanged.

  • Independent source review passed, including signed endpoint asymmetry and the separate Windows limit.

  • Normal commit hooks passed.

  • Exact CPython 3.14.7 passed the modified full thread snippet and 40 bounded reference probes using already-owned RLocks.

  • Native build and the complete modified thread snippet passed.

  • Unchanged CRLockTests.test_reacquire and CRLockTests.test_timeout passed.

  • Both snippet pytest entries passed under the exact 3.14.7 test runner.

  • Forty bounded native probes preserved recursion state; all targeted cases match the reference. Only the two documented pre-existing fractional-maximum differences remain in that matrix.

  • VM and CAPI Clippy with -D warnings passed.

No full-workspace or Windows-runtime pass is claimed.

Summary by CodeRabbit

  • Bug Fixes
    • Thread lock operations now raise an overflow error for timeout values outside the supported range. Existing validation for non-blocking calls and other invalid timeouts remains in effect.

Preserve CPython signed nanosecond conversion precedence for reentrant and nonblocking acquisition, without changing the platform timeout maximum.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dcf9b684-5196-4d38-8b3a-3e0328cb4da3

📥 Commits

Reviewing files that changed from the base of the PR and between 082a48a and 33ff5ab.


📒 Files selected for processing (2)
  • crates/vm/src/stdlib/_thread.rs
  • extra_tests/snippets/builtin_thread.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.



📝 Walkthrough

Walkthrough

Thread acquire argument validation now checks that timeouts fit within the signed 64-bit nanosecond range. Tests cover out-of-range values and infinities with default blocking and blocking=False.

Changes

Thread timeout validation

Layer / File(s) Summary
Validate timeout range
crates/vm/src/stdlib/_thread.rs, extra_tests/snippets/builtin_thread.py
validate_acquire_args returns an overflow error when a timeout in nanoseconds is outside the signed i64 range. Tests add expected errors for out-of-range values and infinities with both blocking settings.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to 33ff5

The change gives out-of-range timeouts the intended overflow precedence while preserving the sentinel and platform-limit checks. No concrete merge-blocking risk remains; proceed with normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: validating lock timeout range before applying acquire restrictions.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 11:58
@youknowone
youknowone enabled auto-merge (squash) October 10, 2026 11:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T12:04:33.067905Z 33ff5ab Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33ff5abcf2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

(ValueError, {"blocking": False, "timeout": 1}),
(ValueError, {"timeout": -2}),
(OverflowError, {"timeout": _thread.TIMEOUT_MAX + 1}),
(OverflowError, {"blocking": False, "timeout": 2**63 / 1e9}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove prohibited test-data additions

These new timeout rows change the data that drives an existing test, but this repository's critical test-code policy explicitly forbids modifying test data and limits test-file changes to adding or removing expected-failure markers; remove these rows from this file before the change can comply.

AGENTS.md reference: AGENTS.md:L273-L279

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit d23dc63 into RustPython:main Oct 10, 2026
30 checks passed
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.

2 participants