Skip to content

vet: copylock check doesn't detect certain copies #14664

Closed
@valyala

Description

@valyala

copylock check must emit a warning on copying sync.Mutex or struct containing sync.Mutex. It doesn't detect the following cases:

        var a sync.Mutex
        b := a   // doesn't detect
        var c = a  // doesn't detect
        b = a  // detects

See #8005 for details.

Activity

valyala

valyala commented on Mar 6, 2016

@valyala
ContributorAuthor

Submitted a patch for code review - https://go-review.googlesource.com/20254 .

gopherbot

gopherbot commented on Mar 6, 2016

@gopherbot
Contributor

CL https://golang.org/cl/20254 mentions this issue.

valyala

valyala commented on Mar 6, 2016

@valyala
ContributorAuthor

Added yet another patch for detecting locks' copying inside composite literals:

type A struct {
   L sync.Mutex
}

var m sync.Mutex
a := A{
    L: m,   // now this case is detected
}
b := []sync.Mutex{m, a.L}  // and this one
c := map[string]sync.Mutex{"foo": m}  // and this one
valyala

valyala commented on Mar 6, 2016

@valyala
ContributorAuthor
gopherbot

gopherbot commented on Mar 6, 2016

@gopherbot
Contributor

CL https://golang.org/cl/20258 mentions this issue.

josharian

josharian commented on Mar 7, 2016

@josharian
Contributor

Thanks for working on these. I left some comments and asked Rob to take over reviewing once they're addressed (that's what R=r means).

valyala

valyala commented on Mar 13, 2016

@valyala
ContributorAuthor

@josharain, I updated the CL according to comments.

josharian

josharian commented on Mar 13, 2016

@josharian
Contributor

Please ping the CL. (Just write a comment that says "Ping.") Feel free to repeat as needed. I'm leaving the remainder of the review to Rob.

valyala

valyala commented on Jun 22, 2016

@valyala
ContributorAuthor

There is yet another case not covered by cmd/vet:

var a [5]sync.Mutex
b := a // here we copy mutexes by value

Will create a CL for this case.

valyala

valyala commented on Jun 22, 2016

@valyala
ContributorAuthor

See the CL

valyala

valyala commented on Jun 23, 2016

@valyala
ContributorAuthor

Yet another case has been caught and covered by the CL mentioned above:

a := sync.Mutex{}
a = sync.Mutex{}  // here a is overwritten by new value
gopherbot

gopherbot commented on Dec 19, 2016

@gopherbot
Contributor

CL https://golang.org/cl/34630 mentions this issue.

locked and limited conversation to collaborators on Dec 19, 2017
added this to the Go1.7 milestone on Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @josharian@valyala@dmitshur@gopherbot

        Issue actions

          vet: copylock check doesn't detect certain copies · Issue #14664 · golang/go