Skip to content

Comments

Bus adapter changes#4

Closed
riley206-pnnl wants to merge 7 commits intoeclipse-volttron:developfrom
riley206-pnnl:bus_adapter_changes
Closed

Bus adapter changes#4
riley206-pnnl wants to merge 7 commits intoeclipse-volttron:developfrom
riley206-pnnl:bus_adapter_changes

Conversation

@riley206-pnnl
Copy link
Contributor

This pull request introduces several improvements and fixes across the codebase, focusing on enhanced documentation, improved socket handling for IPv6 compatibility, and better error handling in socket operations. The most significant changes are grouped below:

Documentation and Packaging:

  • Major update to the README.md with a clearer project description, installation instructions, dependency details, development guidelines, and disclaimer. Added badges for Python versions, test status, and PyPI version.
  • Updated package version from 2.0.0rc1 to 2.0.0rc2 in pyproject.toml.
  • Fixed the python_version field in the mypy configuration to be a string for consistency.

Socket Handling and Compatibility:

  • Updated usage of getsockname() in both src/protocol_proxy/ipc/asyncio.py and src/protocol_proxy/proxy/asyncio.py to only use the first two elements (host, port), ensuring compatibility with IPv6 sockets which return a 4-tuple. [1] [2]

Error Handling Improvements:

  • Improved error handling in src/protocol_proxy/ipc/gevent.py by wrapping getpeername() calls in try/except blocks to gracefully handle cases where the socket is closed and avoid raising OSError. This change affects logging and exception messages throughout the file for better robustness. [1] [2] [3]

Copy link
Contributor

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 introduces IPv6 socket compatibility improvements, enhanced error handling for closed sockets, updated documentation, and bumped the version to 2.0.0rc2. The main focus is on making socket operations more robust across different network configurations.

  • IPv6 compatibility: Updated getsockname() usage to handle both IPv4 (2-tuple) and IPv6 (4-tuple) return values
  • Error handling: Added try-except blocks around getpeername() calls to gracefully handle closed sockets
  • Documentation: Expanded README with installation instructions, dependencies, and development guidelines

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/protocol_proxy/proxy/asyncio.py Updated socket parameter extraction to support IPv6 by taking only the first two elements from getsockname()
src/protocol_proxy/ipc/asyncio.py Applied the same IPv6 compatibility fix for inbound server socket parameters
src/protocol_proxy/ipc/gevent.py Added error handling for getpeername() calls to prevent crashes when sockets are closed, though several string formatting issues were introduced
pyproject.toml Bumped version to 2.0.0rc2 and fixed mypy python_version to be a string
README.md Comprehensive documentation update with badges, installation instructions, and disclaimer, but contains two typos

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +235 to +238
peer_name = f'to {s.getpeername()}'
except OSError:
peer_name = ''
_log.warning(f'Outbound socket to {peer_name} was ready, but no outbound message was found.')
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formatting issue: The log message is missing "socket" between "Outbound" and the peer name. It should be f'Outbound socket {peer_name} was ready, but no outbound message was found.' When peer_name is empty, it produces "Outbound socket to was ready" which is grammatically incorrect, and when it's populated, it produces "Outbound socket to to [address]" with duplicate "to".

Suggested change
peer_name = f'to {s.getpeername()}'
except OSError:
peer_name = ''
_log.warning(f'Outbound socket to {peer_name} was ready, but no outbound message was found.')
peer_name = s.getpeername()
except OSError:
peer_name = None
if peer_name:
_log.warning(f'Outbound socket {peer_name} was ready, but no outbound message was found.')
else:
_log.warning('Outbound socket was ready, but no outbound message was found.')

Copilot uses AI. Check for mistakes.
Comment on lines 208 to +209
_log.warning(f'{self.proxy_name}: Received unknown method name: {headers.method_name}'
f' from {s.getpeername()} with request ID: {headers.request_id}')
f' {peer_name} with request ID: {headers.request_id}')
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formatting issue: The log message has an extra space before {peer_name}. It should be f'{self.proxy_name}: Received unknown method name: {headers.method_name}{peer_name} with request ID: {headers.request_id}' (without the space before {peer_name}). When peer_name is empty, it produces an extra space, and when it's populated with from [address], it already has a leading space.

Copilot uses AI. Check for mistakes.
if len(received) == 0:
_log.warning(f'{self.proxy_name} received closed socket from ({s.getpeername()}.')
try:
peer_name = f' from {s.getpeername()}.'
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formatting issue: When getpeername() succeeds, peer_name is set to f' from {s.getpeername()}.' (with a trailing period), but the log message is f'{self.proxy_name} received closed socket {peer_name}' which will produce a period in the middle of the sentence when the peer name is available. The period should be removed from the peer_name assignment on line 150, or added to line 153 after {peer_name}.

Suggested change
peer_name = f' from {s.getpeername()}.'
peer_name = f' from {s.getpeername()}'

Copilot uses AI. Check for mistakes.
raise NotImplementedError(f'Unknown protocol version ({version_num})'
f' received from: {s.getpeername()}')
try:
peer_name = f' received from: {s.getpeername()}.'
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formatting issue: When getpeername() succeeds, peer_name is set to f' received from: {s.getpeername()}.' (with a trailing period), but this creates double periods in the error message. The period should be removed from the peer_name assignment on line 158, or the message should be structured differently to avoid duplication.

Suggested change
peer_name = f' received from: {s.getpeername()}.'
peer_name = f' received from: {s.getpeername()}'

Copilot uses AI. Check for mistakes.
Comment on lines +213 to +216
peer_name = f': {s.getpeername()}.'
except OSError:
peer_name = '.'
_log.warning(f'{self.proxy_name}: Unable to read headers from socket: {peer_name}')
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String formatting issue: When getpeername() succeeds, peer_name is set to f': {s.getpeername()}.' (with a leading colon and trailing period), but the log message already has : before it, creating double colons: "Unable to read headers from socket: : [address].". The leading colon should be removed from the peer_name assignment on line 213.

Suggested change
peer_name = f': {s.getpeername()}.'
except OSError:
peer_name = '.'
_log.warning(f'{self.proxy_name}: Unable to read headers from socket: {peer_name}')
peer_name = f' {s.getpeername()}'
except OSError:
peer_name = ''
_log.warning(f'{self.proxy_name}: Unable to read headers from socket:{peer_name}')

Copilot uses AI. Check for mistakes.
[![Passing?](https://github.com/eclipse-volttron/lib-protocol-proxy/actions/workflows/run-tests.yml/badge.svg)](https://github.com/eclipse-volttron/lib-protocol-proxy/actions/workflows/run-tests.yml)
[![pypi version](https://img.shields.io/pypi/v/protocol-proxy.svg)](https://pypi.org/project/protocol-proxy/)

This library provides the user with the ability to automatically deploy and manager proxy processes for handling
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "manager": "the ability to automatically deploy and manager proxy processes" should be "the ability to automatically deploy and manage proxy processes".

Suggested change
This library provides the user with the ability to automatically deploy and manager proxy processes for handling
This library provides the user with the ability to automatically deploy and manage proxy processes for handling

Copilot uses AI. Check for mistakes.
```

Protocol Proxy plugins should include "protocol-proxy" as a requirement, so users of existing
plugins are encouraged to instead install the plugin for that pacakge directly.
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "pacakge": "install the plugin for that pacakge directly" should be "install the plugin for that package directly".

Suggested change
plugins are encouraged to instead install the plugin for that pacakge directly.
plugins are encouraged to instead install the plugin for that package directly.

Copilot uses AI. Check for mistakes.
@davidraker
Copy link
Contributor

Commits in this PR are included in another PR. They will be merged there.

@davidraker davidraker closed this Feb 12, 2026
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.

2 participants