Conversation
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
|
This PR has been superseded by #55, which takes the same Connection wrapper approach but also fixes the deprecated aiohttp WebSocket API calls in |
|
This has been superseded by #59 with an updated fix for the same issue. The new PR includes a runtime patch approach that works with both caldera 5.0.0 and the current main branch. Thank you for the original work identifying and diagnosing this! |
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: