Skip to content

Conversation

@garmr-ulfr
Copy link
Collaborator

@garmr-ulfr garmr-ulfr commented Dec 17, 2025

This PR refactors the client context tracking architecture to fix a critical bug where the client information was being stored in the global registry and overwriting it on each new connection.

Key changes include:

New architecture for client context tracking

  • Introduced ClientContextInjector in injector.go for sending client info from the client side, and Manager in manager.go for receiving and managing client info on the server side, replacing the previous unified ClientContextTracker. This separation clarifies responsibilities and improves maintainability. [1] [2] [3] [4] [5]

Context propagation and extensibility

  • The server-side Manager stores client info in connection context and allows other trackers to access it through ClientInfoFromContext, enabling richer downstream processing.

Documentation and cleanup

  • Updated and expanded documentation to clarify usage patterns and the new architecture, and removed the legacy ClientContextTracker implementation. Also cleaned up unused imports in tracker_test.go. [1] [2]

Copilot AI review requested due to automatic review settings December 17, 2025 01:44
@garmr-ulfr
Copy link
Collaborator Author

garmr-ulfr commented Dec 17, 2025

After #75 is merged, this can be rebased, so it reflects the actual changes. Rebased.

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 refactors the client context tracking architecture to fix a critical bug where the global registry was being overwritten by each new connection. The new architecture separates client-side and server-side responsibilities for better maintainability and proper context isolation.

  • Introduced ClientContextInjector for client-side injection of client info and Manager for server-side management, replacing the monolithic ClientContextTracker
  • Changed the protocol from simple JSON exchange to HTTP-based communication (POST /clientinfo with HTTP 200 OK response) for stream connections, and prefixed packets for datagram connections
  • Updated tests to validate both scenarios: with and without client context tracking

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
tracker/clientcontext/tracker.go Removed the old ClientContextTracker implementation and all connection wrapper types; retained only shared types (ClientInfo, MatchBounds, boundsRule) and updated package documentation
tracker/clientcontext/manager.go New server-side component that reads client info from connections, stores it in context, and propagates it to registered trackers
tracker/clientcontext/injector.go New client-side component that sends client info to the server after connection handshake using HTTP POST requests
tracker/clientcontext/tracker_test.go Restructured integration tests with separate subtests for scenarios with and without client context tracking; removed unused imports

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

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.


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

req.Write(buf)
if _, err = conn.Write(req.Bytes()); err != nil {
return fmt.Errorf("writing client info: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just use a normal http.Request here and then err := req.Write(conn) I think?

@garmr-ulfr garmr-ulfr merged commit 3f781f8 into main Dec 18, 2025
1 check passed
@garmr-ulfr garmr-ulfr deleted the context-tracker-manager branch December 18, 2025 20:05
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.

4 participants