Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/analysis/passes/waitgroup: report re-assignment of sync.WaitGroup variables #71357

Open
merrickclay opened this issue Jan 21, 2025 · 0 comments
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@merrickclay
Copy link
Contributor

merrickclay commented Jan 21, 2025

Proposal Details

Reassignment of variables of type sync.WaitGroup is likely to cause bugs due to the potential to overwrite a WaitGroup with a non-zero counter value with a WaitGroup that has a zero counter. I can't think of any scenarios whereby reassigning a variable of type sync.WaitGroup would be required or useful. The waitgroup analysis pass should be extended to report reassignments of sync.WaitGroup variables.

Example

package main

import (
	"sync"
)

type Object struct {
	wg sync.WaitGroup
}

var wg0 sync.WaitGroup

func main() {
	var wg1 sync.WaitGroup                    // ok
	wg2 := sync.WaitGroup{}                   // ok
	var wg3 sync.WaitGroup = sync.WaitGroup{} // ok

	obj := Object{
		wg: sync.WaitGroup{},  // ok
	}

	wg0 = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned
	wg1 = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned

	obj.wg = sync.WaitGroup{} // want: variable of type sync.WaitGroup reassigned

	wg0.Wait()
	wg1.Wait()
	wg2.Wait()
	wg3.Wait()
}

Should this proposal be approved, I'd like to contribute the aforementioned changes.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 21, 2025
@gopherbot gopherbot added this to the Unreleased milestone Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants