Skip to content

fix: handle IPv6 getpeername tuple (#20)#22

Merged
6C656C65 merged 4 commits intomainfrom
fix/20
May 6, 2026
Merged

fix: handle IPv6 getpeername tuple (#20)#22
6C656C65 merged 4 commits intomainfrom
fix/20

Conversation

@6C656C65
Copy link
Copy Markdown
Member

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

What is the current behavior?

When calling server_socket.getpeername(), the code assumes the returned value is always a 2-element tuple (host, port).

However, with IPv6 connections, the method returns a 4-element tuple (host, port, flowinfo, scopeid), which causes unpacking errors such as:

ValueError: too many values to unpack (expected 2)

This breaks the application when handling IPv6 requests.

Issue Number: #20

What is the new behavior?

  • Properly handles both IPv4 and IPv6 tuple formats returned by getpeername()
  • Extracts only host and port in a safe and version-agnostic way
  • Adds test coverage to reproduce the issue and validate the fix
  • Ensures compatibility regardless of the underlying IP protocol used by the client

Other information

@6C656C65 6C656C65 self-assigned this Apr 30, 2026
@6C656C65 6C656C65 marked this pull request as draft April 30, 2026 16:29
Comment thread pyproxy/handlers/https.py Outdated
else:
target_ip, target_port, *_ = peer

target_ip, target_port = server_socket.getpeername()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove this line or you still get the problem.

@6C656C65 6C656C65 marked this pull request as ready for review May 6, 2026 16:10
@6C656C65 6C656C65 merged commit 3f9e065 into main May 6, 2026
16 checks passed
@6C656C65 6C656C65 deleted the fix/20 branch May 6, 2026 16:12
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