fix 5079: only log msg when the channel is not closed (#5132)

This commit is contained in:
Ming Deng 2022-12-22 10:47:01 +08:00 committed by GitHub
parent e4109d09d6
commit eac6c3a4cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -3,6 +3,7 @@
- [add read through for cache module](https://github.com/beego/beego/pull/5116)
- [add singleflight cache for cache module](https://github.com/beego/beego/pull/5119)
- [Fix 5129: must set formatter after init the logger](https://github.com/beego/beego/pull/5130)
- [Fix 5079: only log msg when the channel is not closed](https://github.com/beego/beego/pull/5132)
# v2.0.7
- [Upgrade github.com/go-kit/kit, CVE-2022-24450](https://github.com/beego/beego/pull/5121)

View File

@ -225,7 +225,7 @@ func (bl *BeeLogger) SetLogger(adapterName string, configs ...string) error {
func (bl *BeeLogger) DelLogger(adapterName string) error {
bl.lock.Lock()
defer bl.lock.Unlock()
outputs := []*nameLogger{}
outputs := make([]*nameLogger, 0, len(bl.outputs))
for _, lg := range bl.outputs {
if lg.name == adapterName {
lg.Destroy()
@ -360,9 +360,13 @@ func (bl *BeeLogger) startLogger() {
gameOver := false
for {
select {
case bm := <-bl.msgChan:
bl.writeToLoggers(bm)
logMsgPool.Put(bm)
case bm, ok := <-bl.msgChan:
// this is a terrible design to have a signal channel that accept two inputs
// so we only handle the msg if the channel is not closed
if ok {
bl.writeToLoggers(bm)
logMsgPool.Put(bm)
}
case sg := <-bl.signalChan:
// Now should only send "flush" or "close" to bl.signalChan
bl.flush()
@ -603,7 +607,10 @@ func (bl *BeeLogger) flush() {
if bl.asynchronous {
for {
if len(bl.msgChan) > 0 {
bm := <-bl.msgChan
bm, ok := <-bl.msgChan
if !ok {
continue
}
bl.writeToLoggers(bm)
logMsgPool.Put(bm)
continue