Go

Go

Made by DeepSource

sync.Mutex or sync.RWMutex methods exposed GO-W4013

Bug risk
Major

Exposing sync.Mutex or sync.RWMutex allows the caller to Lock or Unlock the underlying mutex, potentially leading to a deadlock.

Bad practice

package main

import (
    "sync"
)

type Foo struct {
    sync.Mutex
    A int
}

Recommended

package main

import (
    "sync"
)

type Foo struct {
    A int
    lock sync.Mutex
}