Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonEncoder.safeAddString panic #1264

Open
fudali113 opened this issue Mar 27, 2023 · 8 comments
Open

jsonEncoder.safeAddString panic #1264

fudali113 opened this issue Mar 27, 2023 · 8 comments

Comments

@fudali113
Copy link

func (enc *jsonEncoder) safeAddString(s string) {

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
Copy link
Contributor

sywhang commented Mar 27, 2023

Hey there,

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

@raymondlukanta
Copy link

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

@xiangyuwu-gif
Copy link

xiangyuwu-gif commented Jan 8, 2024

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

@xiangyuwu-gif
Copy link

func (enc *jsonEncoder) safeAddString(s string) {

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
Copy link

lzakharov commented Apr 22, 2024

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/[email protected]/zapcore/json_encoder.go:490 +0x54
go.uber.org/zap/zapcore.(*jsonEncoder).AppendString(0xc0376cd500, {0x0, 0x5c})
	go.uber.org/[email protected]/zapcore/json_encoder.go:295 +0x1f9
go.uber.org/zap/zapcore.(*jsonEncoder).AddString(0xc037697ce0?, {0x20a22ee?, 0x30?}, {0x0, 0x5c})
	go.uber.org/[email protected]/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/[email protected]/zapcore/field.go:149 +0x466
go.uber.org/zap/zapcore.addFields(...)
	go.uber.org/[email protected]/zapcore/field.go:210
go.uber.org/zap/zapcore.(*ioCore).With(0xc037697a70, {0xc0376cd4c0, 0x1, 0x7facc1e28d40?})
	go.uber.org/[email protected]/zapcore/core.go:83 +0x1a5
go.uber.org/zap/zapcore.(*sampler).With(0xc0376cd300, {0xc0376cd4c0?, 0x455de9?, 0x20?})
	go.uber.org/[email protected]/zapcore/sampler.go:205 +0x2c

@r-hang
Copy link
Contributor

r-hang commented Apr 23, 2024

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
Copy link

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
Copy link

lzakharov commented Apr 27, 2024

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/[email protected]/zapcore/json_encoder.go:527 +0x54
go.uber.org/zap/zapcore.(*jsonEncoder).safeAddString(...)
	go.uber.org/[email protected]/zapcore/json_encoder.go:489
go.uber.org/zap/zapcore.(*jsonEncoder).AppendString(0xc003f8d500, {0x0, 0x5c})
	go.uber.org/[email protected]/zapcore/json_encoder.go:295 +0x219
go.uber.org/zap/zapcore.(*jsonEncoder).AddString(0xc00ad16810?, {0x215c17e?, 0x30?}, {0x0, 0x5c})
	go.uber.org/[email protected]/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/[email protected]/zapcore/field.go:149 +0x466
go.uber.org/zap/zapcore.addFields(...)
	go.uber.org/[email protected]/zapcore/field.go:210
go.uber.org/zap/zapcore.(*ioCore).With(0xc00ad16330, {0xc003f8d4c0, 0x1, 0x7f3883e4b4c8?})
	go.uber.org/[email protected]/zapcore/core.go:83 +0x1a5
go.uber.org/zap/zapcore.(*sampler).With(0xc003f8cbc0, {0xc003f8d4c0?, 0x455e29?, 0x20?})
	go.uber.org/[email protected]/zapcore/sampler.go:205 +0x2c

Still trying to catch this case locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants