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

连续调用两次netpack.tostring导致的lua crash #527

Closed
zhust2003 opened this issue Jul 1, 2016 · 3 comments
Closed

连续调用两次netpack.tostring导致的lua crash #527

zhust2003 opened this issue Jul 1, 2016 · 3 comments

Comments

@zhust2003
Copy link
Contributor

你好,我是昨天晚上在群里提问题的Dalton,因为今天公司空调坏了,所以到现在才去分析问题。
昨晚的问题是在query_string的地方出现了一次lua crash,内存问题比较难以定位,昨晚去掉了jemalloc后,帮助我更快的找到了问题点,是double free导致的,gdb到core文件中定位到了问题原因。
(gdb) bt
#0 0x00007fd904ea8625 in raise () from /lib/libc.so.6
#1 0x00007fd904ea9e05 in abort () from /lib/libc.so.6
#2 0x00007fd904ee6537 in __libc_message () from /lib/libc.so.6
#3 0x00007fd904eebf4e in malloc_printerr () from /lib/libc.so.6
#4 0x00007fd904eeecad in _int_free () from /lib/libc.so.6
#5 0x00007fd8fc523886 in ltostring (L=0x7fd8f40a6798) at lualib-src/lua-netpack.c:460

去掉jemalloc后,glibc在之前crash之前已经定位到了double free,最近有用的堆栈是在5,然后我去看了下我的lua代码,是这样的一份代码,当时为了临时打印东西写的。
184 local function dispatch_msg(fd, msg, sz)
185 print(string.format("recv message from fd (%d) : %s", fd, crypt.hexencode(netpack.tostring(msg,sz))))
186 messages:pushBack(netpack.tostring(msg,sz))
也就是我调用了两次netpack.tostring出现了double free,我注释了print代码就ok了,看了netpack.tostring中确有free代码。

@zhust2003
Copy link
Contributor Author

云风可以看看真实原因,因为我只看到这部分就没往下看了,先提交上来,也有可能是我的问题

@zhust2003
Copy link
Contributor Author

想了下,应该就是msg被free两次导致后面的一系列问题,看样子msg的释放只会在这里进行,也就是说调用这个netpack.tostring要进行一次,且要非常小心,不知道有没有更好的写法能规避这个问题,目前我也没想到好的方案。

@cloudwu
Copy link
Owner

cloudwu commented Jul 1, 2016

这里有解释: https://github.com/cloudwu/skynet/wiki/GateServer

netpack 是一个内部库,只是为 gate 实现做的,不建议直接使用。

ps. 可使用 skynet.tostring 不销毁内存。

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