Skip to content

Index send_all memoryviews by byte count, not element count - #3545

Closed
Eryx-Z wants to merge 2 commits into
python-trio:mainfrom
Eryx-Z:fix/3543-send-all-memoryview-bytes
Closed

Eryx-Z wants to merge 2 commits into
python-trio:mainfrom
Eryx-Z:fix/3543-send-all-memoryview-bytes

Conversation

@Eryx-Z

@Eryx-Z Eryx-Z commented Oct 17, 2026

Copy link
Copy Markdown

Summary

SocketStream.send_all and POSIX FdStream.send_all used byte counts from send() / os.write() as memoryview element offsets. For a contiguous view with itemsize > 1, a partial write could skip data and return successfully without sending the full buffer.

Cast nonempty contiguous views to a one-dimensional bytes view before slicing so offsets and lengths stay in bytes.

Fixes #3543.

Test plan

  • New FdStream regression with memoryview(...).cast("H") over a pipe
  • Existing test_SocketStream_send_all / pipe send tests still pass

Eryx-Z and others added 2 commits October 17, 2026 08:09
SocketStream and FdStream treated send()/os.write() return values as
element offsets into the memoryview. For contiguous views with
itemsize > 1, a partial write skipped data and returned success early.

Cast nonempty contiguous views to a 1-D bytes view before slicing.

Fixes python-trio#3543.
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.90476% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.95896%. Comparing base (4630d02) to head (0e9a80c).

Files with missing lines Patch % Lines
src/trio/_tests/test_unix_pipes.py 56.25000% 7 Missing ⚠️
src/trio/_highlevel_socket.py 50.00000% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##                 main       #3545         +/-   ##
====================================================
- Coverage   100.00000%   99.95896%   -0.04104%     
====================================================
  Files             128         128                 
  Lines           19474       19494         +20     
  Branches         1323        1326          +3     
====================================================
+ Hits            19474       19486         +12     
- Misses              0           7          +7     
- Partials            0           1          +1     
Files with missing lines Coverage Δ
src/trio/_unix_pipes.py 100.00000% <100.00000%> (ø)
src/trio/_highlevel_socket.py 99.15966% <50.00000%> (-0.84034%) ⬇️
src/trio/_tests/test_unix_pipes.py 95.73171% <56.25000%> (-4.26829%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@A5rocks

A5rocks commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Same as the other PR, I'm not willing to guide an LLM step by step into contributing. I can do that myself!

(and I don't really get why you'd want to special case contiguous memory views...?)

@A5rocks A5rocks closed this Oct 17, 2026
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.

send_all can silently truncate typed memoryviews after partial writes

2 participants