Skip to content

Commit

Permalink
fix 5079: only log msg when the channel is not closed (#5132)
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Dec 22, 2022
1 parent e4109d0 commit eac6c3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions core/logs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eac6c3a

Please sign in to comment.