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

go/token: AddFile API is racy #5418

Closed
bradfitz opened this issue May 6, 2013 · 3 comments
Closed

go/token: AddFile API is racy #5418

bradfitz opened this issue May 6, 2013 · 3 comments

Comments

@bradfitz
Copy link
Contributor

bradfitz commented May 6, 2013

go/token's FileSet AddFile is:

func (s *FileSet) AddFile(filename string, base, size int) *File

But the "base" parameter is typically from s.Base().

(*FileSet).Base() is protected by a mutex, but one that is locked and unlocked before
AddFile also acquires it.

That means two goroutines can allocate the same base and blow up in
go/parser.Parser.AddFile -> token.FileSet.AddFile.

If FileSet's AddFile's base accepted a negative number to mean "you allocate the
base, from fs.Base()", then it could be under the same lock and the higher-level
race would be removed.

And it wouldn't be changing the API.
@bradfitz
Copy link
Contributor Author

bradfitz commented May 7, 2013

Comment 1:

Not yet mailed, but: https://golang.org/cl/9269043

@dsymonds
Copy link
Contributor

Comment 2:

Labels changed: added priority-soon, removed priority-triage.

Owner changed to @bradfitz.

@bradfitz
Copy link
Contributor Author

Comment 3:

This issue was closed by revision 67acff0.

Status changed to Fixed.

@bradfitz bradfitz self-assigned this May 14, 2013
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants