Skip to content

Validate RLock acquisition arguments before reentrant success - #9035

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-rlock-argument-validation
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-rlock-argument-validation

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Validate RLock.acquire() arguments before the reentrant fast path. Invalid non-blocking/time-out combinations, negative timeouts, and excessive timeouts must raise without increasing the recursion count, matching CPython 3.14.

Extracted from #8954. The shared argument check also preserves ordinary Lock validation. Adds a focused owned-lock regression to the existing thread snippet; canonical tests retain the general lock coverage.

Validation:

  • CPython 3.14.7 passes the snippet. The pre-fix RustPython baseline accepts all three invalid reentrant calls and increments the count.
  • Normal pre-commit hooks and VM Clippy pass.
  • Patched native runtime and aggregate tests await CI; local runtime linking is blocked by available disk space.

AI-assisted implementation, tests, and review with OpenAI Codex. Kept as a draft for CI and maintainer review.

Extract the Python 3.14-compatible timeout validation order from RustPython#8954. Share validation with Lock and run it before increasing the RLock recursion count. Keep canonical general-lock coverage and add only owned-lock validation regressions to the existing thread snippet.

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

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81c22f15-5176-403e-bbfc-d6c63ce5e524

📥 Commits

Reviewing files that changed from the base of the PR and between 3af5f8a and b6848a7.


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

  • 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:12
@youknowone
youknowone merged commit 64061cd into RustPython:main Oct 10, 2026
30 checks passed
@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-10T11:16:45.981901Z b6848a7 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: b6848a7530

ℹ️ 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".

from testutils import assert_raises

# Reentrant calls must validate arguments before incrementing the count.
for error, kwargs in (

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 the added test-file logic

This loop adds new test logic and assertions to a test file, but the repository policy says test files may only be changed to remove an expected-failure marker when the test passes or to add one when it cannot be fixed. This addition is neither permitted form, so remove this test-file change rather than expanding the snippet.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

Comment on lines +109 to +112
if !args.blocking && timeout != -1.0 {
return Err(vm.new_value_error("can't specify a timeout for a non-blocking call"));
}
if args.blocking && timeout < 0.0 && timeout != -1.0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Range-check timeouts before combination validation

When an already-owned RLock receives acquire(blocking=False, timeout=_thread.TIMEOUT_MAX + 1), CPython 3.14 raises OverflowError, but this branch runs before the upper-bound check and returns ValueError; +inf follows the same path, while -inf is also misclassified by the following negative-value branch. Because the commit newly routes reentrant acquisition through this validator, out-of-range calls still get the wrong exception; validate both bounds and finiteness before applying the blocking/sign rules.

AGENTS.md reference: AGENTS.md:L7-L7

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed against exact CPython 3.14.7 and native main. Follow-up draft #9061 checks the signed nanosecond range before the acquire-specific restrictions, preserving the separate platform limit and -1 sentinel. The modified snippet, unchanged reacquire/timeout tests, both snippet pytest entries, bounded recursion-state probes, normal hooks, and VM/CAPI Clippy pass. The adjacent pre-existing fractional TIMEOUT_MAX discrepancy is explicitly documented and unchanged.

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