Comments (6)
Kubernetes 1.19.0? That didn't use go-logr/zapr yet.
Ah, zap v1.19.0.
from zapr.
Line 228 in df10f47
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.
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.
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.
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.
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)
- Tag a new release HOT 1
- Wrong line reported
- WithName and WithValues should preserve log level HOT 1
- "stacktrace":"github.com/go-logr/zapr.(*zapLogger).Error HOT 3
- How to configured this to log to stdout, not stderr like bizarre Golang standard HOT 1
- Re-pin to a newer zap version
- Bump github.com/go-logr/logr v1.0.0-rc1 => v1.0.0 ?
- Incorrect number of arguments detected HOT 2
- Allow mapping between logr V() and zap log levels HOT 7
- panic messages use keys with spaces HOT 14
- DisableCaller in Zap Config HOT 1
- Why doesn't support semver spec to latest tag? HOT 4
- inconsistent logging of value vs. value embedded somewhere else HOT 2
- warn about malformed parameters HOT 1
- Logr to Zap Level Confusion HOT 3
- use zap.Inline instead of allocating []zap.Field HOT 1
- We are unable to detect the CVE-2020-29652 vulnerability through our vulnerability scanning HOT 1
- Wrong line reported HOT 2
- Build issues on Go 1.21 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zapr.