-
Notifications
You must be signed in to change notification settings - Fork 12
[VIRTS-4793] Fix deprecated socket issues #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes deprecated Python 3 socket issues by introducing a new Connection class that uses read/write streams instead of direct socket usage. The changes modernize socket handling to avoid deprecated APIs.
- Introduces a new
Connectionclass with asyncrecv()andsend()methods using stream-based I/O - Updates the
Sessionclass to accept aConnectionobject with proper type annotation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/c_connection.py | Implements new Connection class with stream-based socket operations |
| app/c_session.py | Updates Session constructor to use Connection type annotation and imports the new class |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| async def send(self, data): | ||
| self.writer.write(data) | ||
| await self.writer.drain() |
Copilot
AI
Oct 6, 2025
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.
The send method doesn't return any value or indicate success/failure. Consider returning the number of bytes written or a success indicator to provide feedback to callers about the operation result.
| await self.writer.drain() | |
| await self.writer.drain() | |
| return len(data) |
| self.writer = writer | ||
|
|
||
| async def recv(self, num_bytes): | ||
| return await self.reader.read(num_bytes) |
Copilot
AI
Oct 6, 2025
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.
The recv method doesn't handle the case where fewer bytes than requested are returned or when EOF is reached. Consider adding error handling or documentation about these edge cases.
| return await self.reader.read(num_bytes) | |
| """ | |
| Read exactly num_bytes bytes from the stream unless EOF is reached. | |
| Returns fewer than num_bytes bytes only if EOF is encountered before enough bytes are read. | |
| """ | |
| data = b'' | |
| while len(data) < num_bytes: | |
| chunk = await self.reader.read(num_bytes - len(data)) | |
| if not chunk: | |
| # EOF reached | |
| break | |
| data += chunk | |
| return data |
|
Can you address the comments above and resubmit for review |
Description
Fixes deprecated Python 3 TransportSocket send/receive issues. Adds new
Connectionobject that makes use of Read/Write streams instead of direct socket usage. Must be merge along with main Caldera repo changes.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: