0

my project use logrus write log to file I use log in multi goroutine and no other thread use the log file but cause this deadlock: code snippets:

    writer, err := rotatelogs.New(
        path.Join(opt.LogDir, opt.LogFile+".%Y-%m-%d"),
        rotatelogs.WithMaxAge(30*24*time.Hour), 
        rotatelogs.WithRotationTime(24*time.Hour), 
        //rotatelogs.WithRotationCount(3),
        //rotatelogs.WithRotationTime(time.Minute),
    )
    if err != nil {
        panic(err)
    }
    lfHook := lfshook.NewHook(writer, ll.Formatter)
    ll.AddHook(lfHook)
goroutine 6 \[semacquire, 11 minutes\]:
internal/poll.runtime_Semacquire(0xc000096840?)
/root/gows/go/src/runtime/sema.go:67 +0x27
internal/poll.(\*fdMutex).rwlock(0xc0000960c0, 0x0?)
/root/gows/go/src/internal/poll/fd_mutex.go:154 +0xd2
internal/poll.(\*FD).writeLock(...)
/root/gows/go/src/internal/poll/fd_mutex.go:239
internal/poll.(\*FD).Write(0xc0000960c0, {0xc0000c2800, 0x71, 0x400})
/root/gows/go/src/internal/poll/fd_unix.go:370 +0x72
os.(\*File).write(...)
/root/gows/go/src/os/file_posix.go:48
os.(\*File).Write(0xc000014018, {0xc0000c2800?, 0x71, 0x0?})
/root/gows/go/src/os/file.go:175 +0x65
go.uber.org/zap/zapcore.multiWriteSyncer.Write({0xc000088860?, 0x2, 0xd57aa0?}, {0xc0000c2800, 0x71, 0x400})
/root/go/pkg/mod/go.uber.org/zap@v1.21.0/zapcore/write_syncer.go:105 +0xae
go.uber.org/zap/zapcore.(\*ioCore).Write(0xc0001b0510, {0x0, {0xc0f9947d6b131bac, 0x98a9a112d2, 0xdaffa0}, {0x0, 0x0}, {0xc0005e4f00, 0x20}, {0x1, ...}, ...}, ...)
/root/go/pkg/mod/go.uber.org/zap@v1.21.0/zapcore/core.go:90 +0xb5
go.uber.org/zap/zapcore.(\*CheckedEntry).Write(0xc0003100c0, {0x0, 0x0, 0x0})
/root/go/pkg/mod/go.uber.org/zap@v1.21.0/zapcore/entry.go:220 +0x1d9
go.uber.org/zap.(\*SugaredLogger).log(0xc000014128, 0x0, {0x9b4487?, 0x11?}, {0xc000076f68?, 0x1?, 0x1?}, {0x0, 0x0, 0x0})
/root/go/pkg/mod/go.uber.org/zap@v1.21.0/sugar.go:227 +0xee
go.uber.org/zap.(\*SugaredLogger).Infof(0xc0005d8ba0?, {0x9b4487?, 0x0?}, {0xc000076f68?, 0x0?, 0x0?})
/root/go/pkg/mod/go.uber.org/zap@v1.21.0/sugar.go:138 +0x45

another condition:

goroutine 1 [sync.Mutex.Lock]:
sync.runtime_SemacquireMutex(0xc00006cc00?, 0x30?, 0x0?)
/root/gows/go/src/runtime/sema.go:77 +0x26
sync.(*Mutex).lockSlow(0xc000135330)
/root/gows/go/src/sync/mutex.go:171 +0x165
sync.(*Mutex).Lock(...)
/root/gows/go/src/sync/mutex.go:90
github.com/sirupsen/logrus.(*MutexWrap).Lock(...)
/root/go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/logger.go:61
github.com/sirupsen/logrus.(*Entry).log(0xc0001dbf10, 0x4, {0xc000215fd0, 0xe})
/root/go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:233 +0x305
github.com/sirupsen/logrus.(*Entry).Log(0xc0001dbf10, 0x4, {0xc00013dea0?, 0x10?, 0x909560?})
/root/go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:304 +0x4f
github.com/sirupsen/logrus.(*Logger).Log(0xc000135300, 0x4, {0xc00013dea0, 0x1, 0x1})
/root/go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/logger.go:204 +0x65
github.com/sirupsen/logrus.(*Logger).Info(...)
/root/go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/logger.go:226
netgo/common/logs.(*LogrusLogger).Info(0x3b9aca00?, {0x9baf6b?, 0xe?}, {0x0?, 0x0?, 0x0?})
/root/root/gows/netgo/common/logs/logrus.go:63 +0x72

what cause that? i as try zap and other log frame ,has same problem who can commond a easy use log library for go?

dtdyq
  • 11
  • 1
  • can you add a simple code to reproduce this bug? – Para Mar 07 '23 at 07:49
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 07 '23 at 07:55
  • logrus init code: writer, err := rotatelogs.New( path.Join(opt.LogDir, opt.LogFile+".%Y-%m-%d"), rotatelogs.WithMaxAge(30*24*time.Hour), rotatelogs.WithRotationTime(24*time.Hour), //rotatelogs.WithRotationCount(3), //rotatelogs.WithRotationTime(time.Minute), ) if err != nil { panic(err) } lfHook := lfshook.NewHook(writer, ll.Formatter) ll.AddHook(lfHook) – dtdyq Mar 07 '23 at 09:19

0 Answers0