GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix ssl MSG_PEEK by youknowone · Pull Request #6892 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Jan 29, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Improved SSL/TLS socket shutdown behavior to reliably distinguish encrypted records from post-TLS cleartext, preventing data loss and ensuring correct connection close handling.
  • Tests

    • Added tests ensuring sorting uses the expected comparison method (verifying lt is used and gt is not), including reverse-order scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds socket-peek-based TLS shutdown/read logic to the SSL module to distinguish TLS records from post-TLS cleartext during close-notify handling, plus a private helper to consume exactly one TLS record when appropriate. Also adds tests tracking comparison calls in sorting.

Changes

Cohort / File(s) Summary
TLS socket & TLS shutdown logic
crates/stdlib/src/ssl.rs
Added sock_peek (pub(crate)) and try_read_close_notify_socket (private). Updated non-BIO shutdown/read paths to use MSG_PEEK to detect TLS records vs post-TLS cleartext, consume exactly one TLS record when needed, and invoke process_new_packets after reading TLS data. Adjusted socket recv/send usage in shutdown flows.
Sorting comparison tests
extra_tests/snippets/builtin_list.py
Added TrackComparison helper and tests asserting sorted()/list.sort() use __lt__ (not __gt__), including reverse=True cases; updated assertion formatting.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PySSLSocket
    participant Socket
    participant TlsConnection
    participant VM

    Client->>Socket: send data (may be TLS record or cleartext)
    PySSLSocket->>Socket: sock_peek(size)  -- MSG_PEEK
    Socket-->>PySSLSocket: peeked bytes
    PySSLSocket->>TlsConnection: analyze peeked bytes (record header)
    alt TLS record present
        PySSLSocket->>Socket: sock_recv(exact_record_len)
        Socket-->>PySSLSocket: TLS record bytes
        PySSLSocket->>TlsConnection: feed bytes, process_new_packets()
        TlsConnection-->>PySSLSocket: decrypted/plain data
        PySSLSocket->>VM: return decrypted data / handle close-notify
    else Post-TLS cleartext
        PySSLSocket-->>VM: treat peeked bytes as cleartext (do not consume TLS)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • fix ssl MSG_PEEK #6892: Modifies same ssl.rs helpers and introduces peek-based TLS shutdown/read logic.
  • better ssl write handling #6763: Overlaps on PySSLSocket I/O and shutdown/read handling around close-notify and process_new_packets.
  • Share more ssl consts and fix openssl  #6462: Related changes to SSL read/shutdown behavior and BIO vs socket handling.

Suggested reviewers

  • ShaharNaveh

Poem

"I'm a rabbit with a curious peek,
I nibble bytes but never take a sweep—
Close-notify whispers, I listen right,
I pass along records, keep the rest light.
Hooray for sorts that choose lt to leap!"

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix ssl MSG_PEEK' directly corresponds to the primary change: implementing MSG_PEEK-based socket peeking for SSL/TLS shutdown handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
  • ruff format
    Please pull the latest changes before pushing again:
git pull origin fix-ssl
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
fix ssl MSG_PEEK
b3d0d0d
@youknowone
youknowone marked this pull request as ready for review January 29, 2026 07:00
@youknowone
youknowone force-pushed the fix-ssl branch from db98059 to b3d0d0d Compare January 29, 2026 07:47
@youknowone
youknowone merged commit e363b14 into RustPython:main Jan 29, 2026
11 of 13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone deleted the fix-ssl branch January 29, 2026 07:48
This was referenced Mar 13, 2026
Fix SSL handshake over-reading in STARTTLS #7417
Merged
Fix SSL read over-consuming TCP data and ZeroReturn handling #7418
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

1 participant

@youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.