uber-go / zap

Blazing fast, structured, leveled logging in Go.
https://pkg.go.dev/go.uber.org/zap
MIT License
22.04k stars 1.44k forks source link

jsonEncoder.safeAddString panic #1264

Open fudali113 opened 1 year ago

fudali113 commented 1 year ago

https://github.com/uber-go/zap/blob/845ca51d5b8d9fed9fe14f35ab13b6b160d5762d/zapcore/json_encoder.go#L488

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6e42f8]

goroutine 25244385 [running]: go.uber.org/zap/zapcore.(jsonEncoder).safeAddString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:466 +0x58 go.uber.org/zap/zapcore.(jsonEncoder).AppendString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:267 +0x1f2 go.uber.org/zap/zapcore.(jsonEncoder).AddString(0xc0005d0ca8, {0x2067ce9, 0xc0012e5bf0}, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:182 +0x45 go.uber.org/zap/zapcore.Field.AddTo({{0x2067ce9, 0x7}, 0xf, 0x0, {0x0, 0x4}, {0x0, 0x0}}, {0x24f1be0, 0xc0012e5bf0}) /build/vendor/go.uber.org/zap/zapcore/field.go:149 +0x74c go.uber.org/zap/zapcore.addFields({0x24f1be0, 0xc0012e5bf0}, {0xc0012a6380, 0xe, 0x207236c}) /build/vendor/go.uber.org/zap/zapcore/field.go:210 +0xe6 go.uber.org/zap/zapcore.(jsonEncoder).EncodeEntry(0xc000adbe30, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, 0x3911600}, {0xc00029e0b0, 0xc}, {0x20a7c71, 0x19}, {0x0, ...}, ...}, ...) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:393 +0x671 gopkg.mihoyo.com/takumi/log.zapLogger.write({{0xc00029e0b0, 0xc}, {0xc0009856b0}, {0x24f2860, 0xc000adbe30}, {0x247a798, 0xc000adbe60}}, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, ...}, ...}, ...)

zap version: v1.18.0

I cannot repeat this case, but this error occurs from time to time in our online environment. I hope to get help

sywhang commented 1 year ago

Hey there,

  1. Does this happen with the latest Zap release?
  2. Is there any repro you can provide us with?
raymondlukanta commented 1 year ago

I'm also experiencing the same issue. I'm using version 1.16

xiangyuwu-gif commented 10 months ago

I'm also experiencing the same issue. I'm using version v1.21.0 image

xiangyuwu-gif commented 10 months ago

https://github.com/uber-go/zap/blob/845ca51d5b8d9fed9fe14f35ab13b6b160d5762d/zapcore/json_encoder.go#L488

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6e42f8]

goroutine 25244385 [running]: go.uber.org/zap/zapcore.(jsonEncoder).safeAddString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:466 +0x58 go.uber.org/zap/zapcore.(jsonEncoder).AppendString(0xc0012e5bf0, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:267 +0x1f2 go.uber.org/zap/zapcore.(jsonEncoder).AddString(0xc0005d0ca8, {0x2067ce9, 0xc0012e5bf0}, {0x0, 0x4}) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:182 +0x45 go.uber.org/zap/zapcore.Field.AddTo({{0x2067ce9, 0x7}, 0xf, 0x0, {0x0, 0x4}, {0x0, 0x0}}, {0x24f1be0, 0xc0012e5bf0}) /build/vendor/go.uber.org/zap/zapcore/field.go:149 +0x74c go.uber.org/zap/zapcore.addFields({0x24f1be0, 0xc0012e5bf0}, {0xc0012a6380, 0xe, 0x207236c}) /build/vendor/go.uber.org/zap/zapcore/field.go:210 +0xe6 go.uber.org/zap/zapcore.(jsonEncoder).EncodeEntry(0xc000adbe30, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, 0x3911600}, {0xc00029e0b0, 0xc}, {0x20a7c71, 0x19}, {0x0, ...}, ...}, ...) /build/vendor/go.uber.org/zap/zapcore/json_encoder.go:393 +0x671 gopkg.mihoyo.com/takumi/log.zapLogger.write({{0xc00029e0b0, 0xc}, {0xc0009856b0}, {0x24f2860, 0xc000adbe30}, {0x247a798, 0xc000adbe60}}, {0x0, {0xc1005e92872d07da, 0x3e5dcd4601bd4, ...}, ...}, ...)

zap version: v1.18.0

I cannot repeat this case, but this error occurs from time to time in our online environment. I hope to get help

hello,how do you fix this problem?update to the latest version?this error also occurs in our online environment sometimes

lzakharov commented 6 months ago

Hi! Any updates on this issue? Got the same panic in our production environment.

Details

go version: 1.22.0 zap version: v1.25.0

panic({0x1d3e9e0?, 0x34e37e0?})
    runtime/panic.go:914 +0x21f
go.uber.org/zap/zapcore.(*jsonEncoder).safeAddString(0xc0376cd500, {0x0, 0x5c})
    go.uber.org/zap@v1.25.0/zapcore/json_encoder.go:490 +0x54
go.uber.org/zap/zapcore.(*jsonEncoder).AppendString(0xc0376cd500, {0x0, 0x5c})
    go.uber.org/zap@v1.25.0/zapcore/json_encoder.go:295 +0x1f9
go.uber.org/zap/zapcore.(*jsonEncoder).AddString(0xc037697ce0?, {0x20a22ee?, 0x30?}, {0x0, 0x5c})
    go.uber.org/zap@v1.25.0/zapcore/json_encoder.go:197 +0x3b
go.uber.org/zap/zapcore.Field.AddTo({{0x20a22ee, 0x5}, 0xf, 0x0, {0x0, 0x5c}, {0x0, 0x0}}, {0x249a1d8, 0xc0376cd500})
    go.uber.org/zap@v1.25.0/zapcore/field.go:149 +0x466
go.uber.org/zap/zapcore.addFields(...)
    go.uber.org/zap@v1.25.0/zapcore/field.go:210
go.uber.org/zap/zapcore.(*ioCore).With(0xc037697a70, {0xc0376cd4c0, 0x1, 0x7facc1e28d40?})
    go.uber.org/zap@v1.25.0/zapcore/core.go:83 +0x1a5
go.uber.org/zap/zapcore.(*sampler).With(0xc0376cd300, {0xc0376cd4c0?, 0x455de9?, 0x20?})
    go.uber.org/zap@v1.25.0/zapcore/sampler.go:205 +0x2c
r-hang commented 6 months ago

Hey, we're still looking for a repro case to help us debug and fix this issue. Any leads on one would be appreciated!

lzakharov commented 6 months ago

Okay, we're trying to reproduce this case locally. Also, as I see, the implementation of safeAddString has already changed in v1.26.0. Perhaps this problem is no longer relevant for new versions.

lzakharov commented 6 months ago

Got the same runtime error: invalid memory address or nil pointer dereference with v1.27.0:

panic({0x1de8420?, 0x36187d0?})
    runtime/panic.go:914 +0x21f
go.uber.org/zap/zapcore.safeAppendStringLike[...](0x227cd38?, 0x227cdc0, 0xc00fd719e0, {0x0, 0x5c})
    go.uber.org/zap@v1.27.0/zapcore/json_encoder.go:527 +0x54
go.uber.org/zap/zapcore.(*jsonEncoder).safeAddString(...)
    go.uber.org/zap@v1.27.0/zapcore/json_encoder.go:489
go.uber.org/zap/zapcore.(*jsonEncoder).AppendString(0xc003f8d500, {0x0, 0x5c})
    go.uber.org/zap@v1.27.0/zapcore/json_encoder.go:295 +0x219
go.uber.org/zap/zapcore.(*jsonEncoder).AddString(0xc00ad16810?, {0x215c17e?, 0x30?}, {0x0, 0x5c})
    go.uber.org/zap@v1.27.0/zapcore/json_encoder.go:197 +0x3b
go.uber.org/zap/zapcore.Field.AddTo({{0x215c17e, 0x5}, 0xf, 0x0, {0x0, 0x5c}, {0x0, 0x0}}, {0x2570f98, 0xc003f8d500})
    go.uber.org/zap@v1.27.0/zapcore/field.go:149 +0x466
go.uber.org/zap/zapcore.addFields(...)
    go.uber.org/zap@v1.27.0/zapcore/field.go:210
go.uber.org/zap/zapcore.(*ioCore).With(0xc00ad16330, {0xc003f8d4c0, 0x1, 0x7f3883e4b4c8?})
    go.uber.org/zap@v1.27.0/zapcore/core.go:83 +0x1a5
go.uber.org/zap/zapcore.(*sampler).With(0xc003f8cbc0, {0xc003f8d4c0?, 0x455e29?, 0x20?})
    go.uber.org/zap@v1.27.0/zapcore/sampler.go:205 +0x2c

Still trying to catch this case locally.