Skip to content

Conversation

@bleepbop
Copy link

@bleepbop bleepbop commented Dec 1, 2023

Description

Fixes deprecated Python 3 TransportSocket send/receive issues. Adds new Connection object 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.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@bleepbop bleepbop marked this pull request as ready for review December 19, 2023 21:50
@bleepbop bleepbop requested a review from clenk December 19, 2023 21:50
@deacon-mp deacon-mp requested a review from Copilot October 6, 2025 22:58
Copy link

Copilot AI left a 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 Connection class with async recv() and send() methods using stream-based I/O
  • Updates the Session class to accept a Connection object 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()
Copy link

Copilot AI Oct 6, 2025

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.

Suggested change
await self.writer.drain()
await self.writer.drain()
return len(data)

Copilot uses AI. Check for mistakes.
self.writer = writer

async def recv(self, num_bytes):
return await self.reader.read(num_bytes)
Copy link

Copilot AI Oct 6, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@deacon-mp
Copy link

Can you address the comments above and resubmit for review

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.

3 participants