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

这边不应该去写入rec.Category, 会导致崩溃 #13

Open
huangapple opened this issue Jan 15, 2019 · 4 comments
Open

这边不应该去写入rec.Category, 会导致崩溃 #13

huangapple opened this issue Jan 15, 2019 · 4 comments

Comments

@huangapple
Copy link

pattlog.go 第92行, 你这个rec是传给不止一个goroutine, 是指针传递, 所以在任何goroutine都不要无锁写入, 要不会导致崩溃。

@yangyongzhen
Copy link

这个panic是什么原因导致的呢?使用中又遇到一个导致崩溃的问题
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x455c82]

goroutine 4 [running]:
bytes.(*Buffer).WriteString(0xc043212850, 0x0, 0x7, 0x3, 0x3, 0x0)
D:/Go/src/bytes/buffer.go:188 +0xb1
github.com/jeanphorn/log4go.FormatLogRecord(0x6e6a0f, 0x19, 0xc04339fc70, 0x1, 0x1)
D:/GOPATH/src/github.com/jeanphorn/log4go/pattlog.go:94 +0x3d6
github.com/jeanphorn/log4go.(*ConsoleLogWriter).run(0xc0420022e0, 0x716a80, 0xc042076008)
D:/GOPATH/src/github.com/jeanphorn/log4go/termlog.go:34 +0x77
created by github.com/jeanphorn/log4go.NewConsoleLogWriter
D:/GOPATH/src/github.com/jeanphorn/log4go/termlog.go:26 +0xc6
exit status 2

@huangapple
Copy link
Author

huangapple commented Jan 16, 2019

@yangyongzhen 就是我说的那个原因啊, 他在多线程中去写入一个指针所指向的空间, 导致内存错乱了。在哪报错都有可能, 一般就在附近就崩溃了。
你把pattlog.go第92行 注释掉, 或不要去写入, 改成这样就ok了

			if len(rec.Category) == 0 {
				out.WriteString("DEFAULT")
			} else {
				out.WriteString(rec.Category)
			}

@yangyongzhen
Copy link

收到!多谢啦,我试试

@yangyongzhen
Copy link

是的,问题已解决。是huangapple说的这个问题,感谢!这是作者的一个bug吧,其他的还挺好用,暂未发现其他问题

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

No branches or pull requests

2 participants