Skip to content

fix concurrent socket close#6612

Merged
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:socket
Dec 31, 2025
Merged

fix concurrent socket close#6612
youknowone merged 1 commit intoRustPython:mainfrom
youknowone:socket

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 31, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced socket closing mechanism to ensure proper resource cleanup and prevent potential edge cases during socket shutdown.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The PySocket::close method in socket.rs was refactored to replace detach-based ownership checking with direct socket ownership transfer from the write lock. The new approach closes the socket only when one exists, eliminating explicit INVALID_SOCKET comparisons and simplifying the closing logic.

Changes

Cohort / File(s) Change Summary
Socket close logic refactoring
crates/stdlib/src/socket.rs
Replaced detach-based ownership check in PySocket::close with direct ownership transfer; now calls close_inner(into_sock_fileno(sock)) only when a socket is present, removing explicit INVALID_SOCKET check

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Fix windows socket #6408: Modifies the same socket.rs file and PySocket::close method, adjusting how socket ownership and closing are handled.

Poem

🐰 A socket once closed with a dance,
Now straightforward—no detach romance!
Direct ownership, clear and bright,
No INVALID_SOCKET in sight!
Simplicity hops with delight! 🎉

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3b97ca and 6be2e95.

📒 Files selected for processing (1)
  • crates/stdlib/src/socket.rs

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 and usage tips.

@youknowone youknowone marked this pull request as ready for review December 31, 2025 08:52
@youknowone youknowone merged commit d3afd46 into RustPython:main Dec 31, 2025
12 of 13 checks passed
@youknowone youknowone deleted the socket branch December 31, 2025 08:52
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.

1 participant