Skip to content

Conversation

@garmr-ulfr
Copy link
Collaborator

This just adds getters to the ClientContextInjector and ClientContextManager for the MatchBounds.

Copilot AI review requested due to automatic review settings January 6, 2026 18:57
@garmr-ulfr
Copy link
Collaborator Author

Merging. Minor.

@garmr-ulfr garmr-ulfr merged commit 0f753f7 into main Jan 6, 2026
6 checks passed
@garmr-ulfr garmr-ulfr deleted the matchbounds-getter branch January 6, 2026 18:59
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 adds getter methods for the MatchBounds configuration in both ClientContextInjector and ClientContextManager. It also renames the UpdateBounds method to SetBounds to follow getter/setter naming conventions and ensures the matchBounds field is properly maintained alongside the rule updates.

Key changes:

  • Added matchBounds field to both structs to store the original bounds configuration
  • Renamed UpdateBounds to SetBounds for consistent naming with the new getter
  • Added MatchBounds() getter method with read-lock protection in both structs

Reviewed changes

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

File Description
tracker/clientcontext/manager.go Added matchBounds field storage, renamed UpdateBounds to SetBounds, and implemented thread-safe MatchBounds() getter for Manager
tracker/clientcontext/injector.go Added matchBounds field storage, renamed UpdateBounds to SetBounds, and implemented thread-safe MatchBounds() getter for ClientContextInjector

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

func (m *Manager) MatchBounds() MatchBounds {
m.ruleMu.RLock()
defer m.ruleMu.RUnlock()
return m.matchBounds
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The MatchBounds getter returns a struct containing slices (Inbound and Outbound). While the struct itself is copied, the slices reference the same underlying arrays. This can lead to race conditions if the caller modifies the returned slices or if SetBounds is called concurrently. Consider returning a deep copy of the MatchBounds with copied slices to prevent potential data races.

Suggested change
return m.matchBounds
// Return a deep copy so callers cannot mutate internal slice backing arrays.
bounds := m.matchBounds
if bounds.Inbound != nil {
inboundCopy := make([]string, len(bounds.Inbound))
copy(inboundCopy, bounds.Inbound)
bounds.Inbound = inboundCopy
}
if bounds.Outbound != nil {
outboundCopy := make([]string, len(bounds.Outbound))
copy(outboundCopy, bounds.Outbound)
bounds.Outbound = outboundCopy
}
return bounds

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
func (t *ClientContextInjector) MatchBounds() MatchBounds {
t.ruleMu.RLock()
defer t.ruleMu.RUnlock()
return t.matchBounds
}
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The MatchBounds getter returns a struct containing slices (Inbound and Outbound). While the struct itself is copied, the slices reference the same underlying arrays. This can lead to race conditions if the caller modifies the returned slices or if SetBounds is called concurrently. Consider returning a deep copy of the MatchBounds with copied slices to prevent potential data races.

Copilot uses AI. Check for mistakes.
Comment on lines 123 to +125
m.inboundRule = newBoundsRule(bounds.Inbound)
m.outboundRule = newBoundsRule(bounds.Outbound)
m.matchBounds = bounds
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The matchBounds field is updated after creating the rules from the bounds parameter. For better consistency and to ensure the stored state matches the rules, consider updating matchBounds before creating the rules or at the beginning of the method. This ensures that if bounds is modified after being passed to SetBounds, the matchBounds field reflects the exact state used to create the rules.

Suggested change
m.inboundRule = newBoundsRule(bounds.Inbound)
m.outboundRule = newBoundsRule(bounds.Outbound)
m.matchBounds = bounds
m.matchBounds = bounds
m.inboundRule = newBoundsRule(bounds.Inbound)
m.outboundRule = newBoundsRule(bounds.Outbound)

Copilot uses AI. Check for mistakes.
Comment on lines 88 to +90
t.inboundRule = newBoundsRule(bounds.Inbound)
t.outboundRule = newBoundsRule(bounds.Outbound)
t.matchBounds = bounds
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The matchBounds field is updated after creating the rules from the bounds parameter. For better consistency and to ensure the stored state matches the rules, consider updating matchBounds before creating the rules or at the beginning of the method. This ensures that if bounds is modified after being passed to SetBounds, the matchBounds field reflects the exact state used to create the rules.

Suggested change
t.inboundRule = newBoundsRule(bounds.Inbound)
t.outboundRule = newBoundsRule(bounds.Outbound)
t.matchBounds = bounds
t.matchBounds = bounds
t.inboundRule = newBoundsRule(bounds.Inbound)
t.outboundRule = newBoundsRule(bounds.Outbound)

Copilot uses AI. Check for mistakes.
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