GeezerVison is showing github.com — Align socket receive and control argument binding by youknowdot · Pull Request #9668 · RustPython/RustPython
Conversation
youknowdot
commented
Nov 3, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Share
recv_into/recvfrom_into keyword binding through the VM's existing ArgSpec helper, preserving buffer export and numeric conversion order.
- Return immediately from zero-length
recv and recv_into, including on closed sockets, as CPython does.
- Bind
sendto and setsockopt arguments before conversion, retain original arguments through I/O, and acquire sendto's buffer export before converting flags without holding its data lock across callbacks.
Only production Rust files change. Existing special no-keyword and sendto overload diagnostics remain.
Evidence and validation
Checked CPython 3.15 source (Modules/socketmodule.c: sock_recv_guts, sock_recv_into, sock_recvfrom_into, sock_sendto, and sock_setsockopt). Bounded CPython 3.15.0 probes using only an owned socketpair confirmed:
- Both into-methods accept
buffer, nbytes, and flags keywords.
- Buffer rejection precedes numeric callbacks; valid numeric callbacks precede duplicate/unknown keyword errors.
- Numeric callbacks can mutate exported buffer contents.
- Zero-byte
recv and recv_into return immediately, including after closing the socket.
sendto rejects an invalid buffer before invoking a flags callback.
- Invalid
setsockopt arity does not invoke numeric callbacks.
rustfmt and git diff --check passed. Exact-head cached patches for #9638, #9640, and #9642 each apply cleanly over this change.
Passed on Linux against main 0b081b0283987c7b2d79327dd481f403d515580b:
cargo check -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1
cargo clippy -p rustpython-vm -p rustpython-host_env -p rustpython-stdlib --features rustpython-stdlib/threading --locked --offline -j1 -- -D warnings
RustPython runtime tests, the full Rust suites, Python suites, and other-platform testing were not run. CPython probes establish reference behavior, not execution of the patched RustPython interpreter.
Known limits
The receive methods already had a text-signature mismatch with CPython's keyword support. Their representation now becomes generic (*args, **kwargs); this patch does not repair introspection metadata. Writable-buffer error wording remains that of the shared buffer helper rather than claiming exact CPython wording.
The zero-byte results above were observed on Linux. On non-poll platforms CPython checks high-descriptor selectability before returning zero, so these observations do not establish blanket cross-platform equivalence.
Independent source review passed with no blocker.
Integration note
#9651 changes ArgSpec::parse_with from Fn to FnMut. This change exposes that existing helper and deliberately does not duplicate #9651's callback change. There is one adjacent-line textual conflict: preserve pub fn parse_with from this change and mut check: impl FnMut from #9651. The receive parser remains compatible with either callback signature.
AI assistance
The source investigation, patch, reference probes, and this draft were prepared with OpenAI Codex assistance under the maintainer's direction. Human review is requested before merge.
Summary by CodeRabbit
- Bug Fixes
- Socket receive operations now return immediately with an empty result when given a zero-length buffer.
- Receive operations validate requested byte counts, including negative and oversized values, with appropriate errors.
- Socket send methods now enforce their supported argument counts and reject keyword arguments where unsupported.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 3, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
Socket receive methods now share argument parsing and return immediately for zero-length requests. sendto and setsockopt also change how they bind arguments and handle conversions.
Changes: Socket argument handling
| Layer / File(s) |
Summary |
Receive argument parsing and behavior crates/stdlib/src/socket.rs |
recv_into and recvfrom_into use shared parsing for the buffer, nbytes, and flags. A zero nbytes selects the full buffer length; negative and oversized values raise errors. recv and recv_into return immediately for zero-length requests. |
sendto and setsockopt argument binding crates/stdlib/src/socket.rs |
sendto checks for two or three positional arguments, converts the payload before flags and address, and delays borrowing payload bytes until conversions finish. setsockopt checks for three or four arguments and binds a clone of the arguments. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Merge Risk: Minimal · up to 35894
-
No actionable merge blocker is established. The changes appear mergeable subject to normal checks; patched-interpreter runtime tests remain unreported.
Pre-merge checks: 4 · 1
-
Failed checks: 1 warning
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
 |
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
Passed checks: 4 passed
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title describes the socket argument binding changes. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
-
Generate unit tests (beta)
-
- 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
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Merging this PR will not alter performance
✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1
Comparing youknowdot:socket-control-binding-group-20261103 (615d672) with main (0b081b0)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 4, 2026
|
|
buf: ArgMemoryBuffer,
|
|
|
nbytes: OptionalArg<isize>,
|
|
|
flags: OptionalArg<i32>,
|
|
|
args: FuncArgs,
|
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.
check this change is necessary after #9563
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Rechecked after #9563. This boundary still needs legacy argument parsing. CPython 3.15's recv_into uses PyArg_ParseTupleAndKeywords("w*|ni:recv_into"), whose conversion loop precedes leftover duplicate/unknown-keyword checks.
For example, recv_into(bytearray(1), IndexRaises(), nbytes=1) must propagate an exception from IndexRaises.__index__() before reporting the duplicate nbytes. Restoring ordinary typed parameters or a derived FromArgs struct would let #9563's Clinic validation reject the duplicate before that callback. I checked this counterexample on the current PR binary and existing CPython 3.12.14; the 3.15 parsing order was checked against the source above.
The safe internal typing is already restored in 358945c: ReceiveIntoArgs::parse uses ArgSpec::bind and typed ArgSlots conversions for ArgMemoryBuffer, isize, and i32, without the old temporary Vec/Cell accumulation. The outer FuncArgs retains the original argument owners through conversion and I/O.
A custom typed FromArgs wrapper is possible, but would still need to opt out of Clinic validation, use this legacy parser, and retain those owners. It would move the boundary rather than eliminate the requirement. Leaving the current boundary unchanged; no new wrapper or common converter is needed here.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reuse keyword parsing for receive buffers, preserve conversion ordering and argument lifetimes, and avoid zero-length receive waits.
Assisted-by: OpenAI Codex:model version not exposed
Keep PyArg_ParseTuple arity diagnostics before the shared binder without changing argument conversion or socket I/O.
Assisted-by: OpenAI Codex:model version not exposed
Use the shared typed legacy argument slots for receive buffers and numeric arguments. Restore typed sendto buffers, setsockopt integer fields, and ArgIndex option lengths while retaining original call owners and overload-specific validation.
Assisted-by: OpenAI Codex:model-version-unavailable
Codex Review Summary: ❌ Failed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
❌ Failed 2026-11-07T07:13:09.067343Z We couldn’t complete this review. Comment @codex review to try again. |
358945c |
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|