Skip to content

Conversation

@djthorpe
Copy link
Member

@djthorpe djthorpe commented Dec 16, 2025

This PR addresses a concurrency issue in the Copy method of the Bind struct by adding proper synchronization when copying the internal vars map. The import statements are also reordered alphabetically.

@djthorpe djthorpe self-assigned this Dec 16, 2025
Copilot AI review requested due to automatic review settings December 16, 2025 06:45
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 addresses a concurrency issue in the Copy method of the Bind struct by adding proper synchronization when copying the internal vars map. The import statements are also reordered alphabetically.

  • Adds read lock protection around the vars map access in the Copy method using an immediately invoked function expression
  • Reorders import statements to place external packages before internal packages

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

varsCopy := func() pgx.NamedArgs {
bind.RLock()
defer bind.RUnlock()
c := make(pgx.NamedArgs, len(bind.vars)+len(pairs)>>1)
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The operator precedence in this expression is incorrect. The right shift operator >> has lower precedence than the addition operator +, so this evaluates as (len(bind.vars) + len(pairs)) >> 1 instead of the intended len(bind.vars) + (len(pairs) >> 1). This causes the map capacity to be calculated as half of the total, when it should be the number of existing vars plus half of the new pairs. Add parentheses to fix the operator precedence.

Suggested change
c := make(pgx.NamedArgs, len(bind.vars)+len(pairs)>>1)
c := make(pgx.NamedArgs, len(bind.vars)+(len(pairs)>>1))
Copilot uses AI. Check for mistakes.
@djthorpe djthorpe merged commit cee3535 into main Dec 16, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant