GithubHelp home page GithubHelp logo

Comments (6)

pohly avatar pohly commented on July 3, 2024

Kubernetes 1.19.0? That didn't use go-logr/zapr yet.

Ah, zap v1.19.0.

from zapr.

pohly avatar pohly commented on July 3, 2024

zapr/zapr.go

Line 228 in df10f47

newLogger.l = zl.l.Named(name)

That's the same line in zapr for the read and write, and the actual write occurs in zap. Can you file a bug in zap for this? This looks like something internal to zap.

from zapr.

pachanga avatar pachanga commented on July 3, 2024

Oh, my bad I meant "I'm using v1.2.3 with zap v1.19.0" :) I'll try to manually re-pin zapr to the newer version of zap and see how it goes.

from zapr.

pachanga avatar pachanga commented on July 3, 2024

After some investigation I think I've figured out why this data race happened and I'm not sure if this is an issue. Here's a simplified pseudo code which triggered a data race:

func newPool(logger logr.Logger) *Pool {
   return &Pool {
        IdleAmount: 16, //<--- spawns 16 goroutines using Dial attribute below
        Dial: func() (Conn, error) {
           logger = logger.WithName("[pool]") //<--- data race error is here
           ...
           return &Conn{logger}
        }
   }
}

It seems the data race happened because newPool's function argument logger was changed by multiple goroutines. Once I rewrote the code as follows the problem was gone:

func newPool(logger logr.Logger) *Pool {
   return &Pool {
        IdleAmount: 16, //<--- spawns 16 goroutines using Dial attribute below
        Dial: func() (Conn, error) {
           newLogger = logger.WithName("[pool]") 
           ...
           return &Conn{newLogger}
        }
   }
}

from zapr.

pohly avatar pohly commented on July 3, 2024

And this Dial callback gets invoked by multiple different goroutines concurrently, right? Yes, that leads to read/write race because one goroutine reads from it while another writes to it.

It's also semantically incorrect: logger = logger.WithName("[pool]") adds "[pool]" to the logger over and over again, making the name longer with each invocation.

from zapr.

pachanga avatar pachanga commented on July 3, 2024

And this Dial callback gets invoked by multiple different goroutines concurrently, right? Yes, that leads to read/write race because one goroutine reads from it while another writes to it.

It's also semantically incorrect: logger = logger.WithName("[pool]") adds "[pool]" to the logger over and over again, making the name longer with each invocation.

Yep, that's right. That was a bug. I guess we can close the issue?

from zapr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.