changed embedded mutex to private field (#217)
Some checks failed
sync / sync (push) Failing after 16m12s
test / test (push) Failing after 17m28s
coverage / build (push) Failing after 17m40s

This commit is contained in:
2025-05-25 03:15:03 +05:00
committed by GitHub
parent 0f8f12aee0
commit 13f90ff716
13 changed files with 151 additions and 151 deletions

View File

@@ -137,7 +137,7 @@ type cache struct {
opts Options
sync.RWMutex
mu sync.RWMutex
}
type cacheEntry struct {
@@ -171,7 +171,7 @@ func (c *cache) put(req string, res string) {
ttl = c.opts.MaxCacheTTL
}
c.Lock()
c.mu.Lock()
if c.entries == nil {
c.entries = make(map[string]cacheEntry)
}
@@ -207,7 +207,7 @@ func (c *cache) put(req string, res string) {
}
c.opts.Meter.Counter(semconv.CacheItemsTotal, "type", "dns").Inc()
c.Unlock()
c.mu.Unlock()
}
func (c *cache) get(req string) (res string) {
@@ -219,8 +219,8 @@ func (c *cache) get(req string) (res string) {
return ""
}
c.RLock()
defer c.RUnlock()
c.mu.RLock()
defer c.mu.RUnlock()
if c.entries == nil {
return ""

View File

@@ -20,7 +20,7 @@ type dnsConn struct {
ibuf bytes.Buffer
obuf bytes.Buffer
sync.Mutex
mu sync.Mutex
}
type roundTripper func(ctx context.Context, req string) (res string, err error)
@@ -42,15 +42,15 @@ func (c *dnsConn) Read(b []byte) (n int, err error) {
}
func (c *dnsConn) Write(b []byte) (n int, err error) {
c.Lock()
defer c.Unlock()
c.mu.Lock()
defer c.mu.Unlock()
return c.ibuf.Write(b)
}
func (c *dnsConn) Close() error {
c.Lock()
c.mu.Lock()
cancel := c.cancel
c.Unlock()
c.mu.Unlock()
if cancel != nil {
cancel()
@@ -78,9 +78,9 @@ func (c *dnsConn) SetDeadline(t time.Time) error {
}
func (c *dnsConn) SetReadDeadline(t time.Time) error {
c.Lock()
c.mu.Lock()
c.deadline = t
c.Unlock()
c.mu.Unlock()
return nil
}
@@ -90,8 +90,8 @@ func (c *dnsConn) SetWriteDeadline(_ time.Time) error {
}
func (c *dnsConn) drainBuffers(b []byte) (string, int, error) {
c.Lock()
defer c.Unlock()
c.mu.Lock()
defer c.mu.Unlock()
// drain the output buffer
if c.obuf.Len() > 0 {
@@ -119,8 +119,8 @@ func (c *dnsConn) drainBuffers(b []byte) (string, int, error) {
}
func (c *dnsConn) fillBuffer(b []byte, str string) (int, error) {
c.Lock()
defer c.Unlock()
c.mu.Lock()
defer c.mu.Unlock()
c.obuf.WriteByte(byte(len(str) >> 8))
c.obuf.WriteByte(byte(len(str)))
c.obuf.WriteString(str)
@@ -128,8 +128,8 @@ func (c *dnsConn) fillBuffer(b []byte, str string) (int, error) {
}
func (c *dnsConn) childContext() (context.Context, context.CancelFunc) {
c.Lock()
defer c.Unlock()
c.mu.Lock()
defer c.mu.Unlock()
if c.ctx == nil {
c.ctx, c.cancel = context.WithCancel(context.Background())
}

View File

@@ -52,7 +52,7 @@ type clientTracer struct {
tr tracer.Tracer
activeHooks map[string]context.Context
root tracer.Span
mtx sync.Mutex
mu sync.Mutex
}
func NewClientTrace(ctx context.Context, tr tracer.Tracer) *httptrace.ClientTrace {
@@ -83,8 +83,8 @@ func NewClientTrace(ctx context.Context, tr tracer.Tracer) *httptrace.ClientTrac
}
func (ct *clientTracer) start(hook, spanName string, attrs ...interface{}) {
ct.mtx.Lock()
defer ct.mtx.Unlock()
ct.mu.Lock()
defer ct.mu.Unlock()
if hookCtx, found := ct.activeHooks[hook]; !found {
var sp tracer.Span
@@ -104,8 +104,8 @@ func (ct *clientTracer) start(hook, spanName string, attrs ...interface{}) {
}
func (ct *clientTracer) end(hook string, err error, attrs ...interface{}) {
ct.mtx.Lock()
defer ct.mtx.Unlock()
ct.mu.Lock()
defer ct.mu.Unlock()
if ctx, ok := ct.activeHooks[hook]; ok { // nolint:nestif
if span, ok := tracer.SpanFromContext(ctx); ok {
if err != nil {
@@ -136,8 +136,8 @@ func (ct *clientTracer) getParentContext(hook string) context.Context {
}
func (ct *clientTracer) span(hook string) (tracer.Span, bool) {
ct.mtx.Lock()
defer ct.mtx.Unlock()
ct.mu.Lock()
defer ct.mu.Unlock()
if ctx, ok := ct.activeHooks[hook]; ok {
return tracer.SpanFromContext(ctx)
}

View File

@@ -14,7 +14,7 @@ type Buffer struct {
vals []*Entry
size int
sync.RWMutex
mu sync.RWMutex
}
// Entry is ring buffer data entry
@@ -35,8 +35,8 @@ type Stream struct {
// Put adds a new value to ring buffer
func (b *Buffer) Put(v interface{}) {
b.Lock()
defer b.Unlock()
b.mu.Lock()
defer b.mu.Unlock()
// append to values
entry := &Entry{
@@ -63,8 +63,8 @@ func (b *Buffer) Put(v interface{}) {
// Get returns the last n entries
func (b *Buffer) Get(n int) []*Entry {
b.RLock()
defer b.RUnlock()
b.mu.RLock()
defer b.mu.RUnlock()
// reset any invalid values
if n > len(b.vals) || n < 0 {
@@ -80,8 +80,8 @@ func (b *Buffer) Get(n int) []*Entry {
// Since returns the entries since a specific time
func (b *Buffer) Since(t time.Time) []*Entry {
b.RLock()
defer b.RUnlock()
b.mu.RLock()
defer b.mu.RUnlock()
// return all the values
if t.IsZero() {
@@ -109,8 +109,8 @@ func (b *Buffer) Since(t time.Time) []*Entry {
// Stream logs from the buffer
// Close the channel when you want to stop
func (b *Buffer) Stream() (<-chan *Entry, chan bool) {
b.Lock()
defer b.Unlock()
b.mu.Lock()
defer b.mu.Unlock()
entries := make(chan *Entry, 128)
id := id.MustNew()

View File

@@ -24,7 +24,7 @@ type stream struct {
err error
request *request
sync.RWMutex
mu sync.RWMutex
}
type request struct {
@@ -57,9 +57,9 @@ func (s *stream) Request() server.Request {
func (s *stream) Send(v interface{}) error {
err := s.Stream.SendMsg(v)
if err != nil {
s.Lock()
s.mu.Lock()
s.err = err
s.Unlock()
s.mu.Unlock()
}
return err
}
@@ -68,17 +68,17 @@ func (s *stream) Send(v interface{}) error {
func (s *stream) Recv(v interface{}) error {
err := s.Stream.RecvMsg(v)
if err != nil {
s.Lock()
s.mu.Lock()
s.err = err
s.Unlock()
s.mu.Unlock()
}
return err
}
// Error returns error that stream holds
func (s *stream) Error() error {
s.RLock()
defer s.RUnlock()
s.mu.RLock()
defer s.mu.RUnlock()
return s.err
}