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

最近程序中采用json来进行序列化,但是经常偶发性出现Segmentation fault.求助! #814

Closed
hanyu363 opened this issue Apr 4, 2018 · 5 comments

Comments

@hanyu363
Copy link
Contributor

hanyu363 commented Apr 4, 2018

coredump文件中提示

warning: Can't read pathname for load map: No error information.
Core was generated by `skynet conf/config.develop'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000555c2162d41b in luaS_remove (L=L@entry=0x7f5ec501b8c8, ts=ts@entry=0x7f5ec5032800) at lstring.c:157
157 lstring.c: No such file or directory.
[Current thread is 1 (LWP 9)]

错误堆栈

#0 0x0000555c2162d41b in luaS_remove (L=L@entry=0x7f5ec501b8c8, ts=ts@entry=0x7f5ec5032800) at lstring.c:157
#1 0x0000555c21627674 in freeobj (o=, L=0x7f5ec501b8c8) at lgc.c:723
#2 sweeplist (L=L@entry=0x7f5ec501b8c8, p=0x7f5ec5031dc0, count=22, count@entry=85) at lgc.c:755
#3 0x0000555c216276fa in sweepstep (L=L@entry=0x7f5ec501b8c8, g=0x7f5ec50c25d8, nextstate=3, nextlist=0x7f5ec50c2640)
at lgc.c:1044
#4 0x0000555c2162796a in singlestep (L=L@entry=0x7f5ec501b8c8) at lgc.c:1088
#5 0x0000555c21627fb6 in luaC_step (L=L@entry=0x7f5ec501b8c8) at lgc.c:1148
#6 0x0000555c2162195c in lua_pushlstring (L=L@entry=0x7f5ec501b8c8, s=, len=) at lapi.c:486
#7 0x0000555c216342bc in luaL_pushresult (B=B@entry=0x7f5ec8250700) at lauxlib.c:544
#8 0x0000555c2163e4d8 in str_format (L=) at lstrlib.c:1091
#9 0x0000555c21624df0 in luaD_precall (L=L@entry=0x7f5ec501b8c8, func=func@entry=0x7f5ec50a40c0, nresults=nresults@entry=-1)
at ldo.c:434
#10 0x0000555c2163102f in luaV_execute (L=L@entry=0x7f5ec501b8c8) at lvm.c:1146
#11 0x0000555c216250bf in luaD_call (L=L@entry=0x7f5ec501b8c8, func=, nResults=nResults@entry=-1) at ldo.c:499
#12 0x0000555c2162269a in lua_pcallk (L=L@entry=0x7f5ec501b8c8, nargs=nargs@entry=0, nresults=nresults@entry=-1,
errfunc=errfunc@entry=2, ctx=ctx@entry=2, k=k@entry=0x555c21638a60 ) at lapi.c:981
#13 0x0000555c21638b20 in luaB_xpcall (L=0x7f5ec501b8c8) at lbaselib.c:441
#14 0x0000555c21624df0 in luaD_precall (L=L@entry=0x7f5ec501b8c8, func=func@entry=0x7f5ec50a3f40, nresults=nresults@entry=-1)
at ldo.c:434
#15 0x0000555c2163102f in luaV_execute (L=L@entry=0x7f5ec501b8c8) at lvm.c:1146
#16 0x0000555c21624b70 in unroll (L=0x7f5ec501b8c8, ud=) at ldo.c:556
#17 0x0000555c21624512 in luaD_rawrunprotected (L=L@entry=0x7f5ec501b8c8, f=f@entry=0x555c21624fc0 ,

#33 0x0000555c21624512 in luaD_rawrunprotected (L=L@entry=0x7f5ec50c2508, f=f@entry=0x555c21620e60 <f_call>,
ud=ud@entry=0x7f5ec8253150) at ldo.c:142
#34 0x0000555c2162542d in luaD_pcall (L=L@entry=0x7f5ec50c2508, func=func@entry=0x555c21620e60 <f_call>,
u=u@entry=0x7f5ec8253150, old_top=48, ef=) at ldo.c:729
#35 0x0000555c21622601 in lua_pcallk (L=L@entry=0x7f5ec50c2508, nargs=nargs@entry=5, nresults=nresults@entry=0,
errfunc=errfunc@entry=1, ctx=ctx@entry=0, k=k@entry=0x0) at lapi.c:969
#36 0x00007f5ec61f8db8 in _cb (context=0x7f5ec50db400, ud=0x7f5ec50c2508, type=3, session=0, source=33, msg=0x7f5ec37bddc0,
sz=54) at lualib-src/lua-skynet.c:52
#37 0x0000555c21619a77 in dispatch_message (ctx=0x7f5ec50db400, msg=0x7f5ec8253240) at skynet-src/skynet_server.c:274
#38 0x0000555c2161a733 in skynet_context_message_dispatch (sm=sm@entry=0x7f5ec7c1e800, q=0x7f5ec50f0840,
weight=weight@entry=-1) at skynet-src/skynet_server.c:334
#39 0x0000555c2161aeb5 in thread_worker (p=) at skynet-src/skynet_start.c:162
#40 0x00007f5ec8066ff8 in ?? () from /lib/ld-musl-x86_64.so.1
#41 0x0000000000000000 in ?? ()

@hanyu363
Copy link
Contributor Author

hanyu363 commented Apr 4, 2018

再次出现,就又换了一个地方。
#0 propagatemark (g=g@entry=0x7f9514e962d8) at lgc.c:574
#1 0x000055d366e53840 in singlestep (L=L@entry=0x7f9510c93008) at lgc.c:1068
#2 0x000055d366e53fb6 in luaC_step (L=L@entry=0x7f9510c93008) at lgc.c:1148
#3 0x000055d366e5ddf3 in luaV_execute (L=L@entry=0x7f9510c93008) at lvm.c:1307
#4 0x000055d366e510bf in luaD_call (L=L@entry=0x7f9510c93008, func=, nResults=nResults@entry=-1) at ldo.c:499
#5 0x000055d366e4e69a in lua_pcallk (L=L@entry=0x7f9510c93008, nargs=nargs@entry=0, nresults=nresults@entry=-1,
errfunc=errfunc@entry=2, ctx=ctx@entry=2, k=k@entry=0x55d366e64a60 ) at lapi.c:981
#6 0x000055d366e64b20 in luaB_xpcall (L=0x7f9510c93008) at lbaselib.c:441
#7 0x000055d366e50df0 in luaD_precall (L=L@entry=0x7f9510c93008, func=func@entry=0x7f9510ca5110, nresults=nresults@entry=-1)
at ldo.c:434
#8 0x000055d366e5d02f in luaV_execute (L=L@entry=0x7f9510c93008) at lvm.c:1146
#9 0x000055d366e50b70 in unroll (L=0x7f9510c93008, ud=) at ldo.c:556
#10 0x000055d366e50512 in luaD_rawrunprotected (L=L@entry=0x7f9510c93008, f=f@entry=0x55d366e50fc0 ,
ud=ud@entry=0x7f95152f4b5c) at ldo.c:142
#11 0x000055d366e511e1 in lua_resume (L=L@entry=0x7f9510c93008, from=from@entry=0x7f9514e96208, nargs=,
nargs@entry=3) at ldo.c:664
#12 0x000055d366e65a77 in auxresume (L=L@entry=0x7f9514e96208, co=co@entry=0x7f9510c93008, narg=3) at lcorolib.c:39
#13 0x000055d366e65db1 in luaB_coresume (L=0x7f9514e96208) at lcorolib.c:60
#14 0x000055d366e50df0 in luaD_precall (L=L@entry=0x7f9514e96208, func=func@entry=0x7f9514e01d70, nresults=nresults@entry=-1)
at ldo.c:434
#15 0x000055d366e5d02f in luaV_execute (L=L@entry=0x7f9514e96208) at lvm.c:1146
#16 0x000055d366e510bf in luaD_call (L=L@entry=0x7f9514e96208, func=, nResults=) at ldo.c:499
---Type to continue, or q to quit---
#17 0x000055d366e51111 in luaD_callnoyield (L=0x7f9514e96208, func=, nResults=) at ldo.c:509
#18 0x000055d366e50512 in luaD_rawrunprotected (L=L@entry=0x7f9514e96208, f=f@entry=0x55d366e4ce60 <f_call>,
ud=ud@entry=0x7f95152f4e70) at ldo.c:142
#19 0x000055d366e5142d in luaD_pcall (L=L@entry=0x7f9514e96208, func=func@entry=0x55d366e4ce60 <f_call>,
u=u@entry=0x7f95152f4e70, old_top=176, ef=) at ldo.c:729
#20 0x000055d366e4e601 in lua_pcallk (L=L@entry=0x7f9514e96208, nargs=5, nresults=nresults@entry=-1, errfunc=errfunc@entry=0,
ctx=ctx@entry=0, k=k@entry=0x55d366e64a60 ) at lapi.c:969
#21 0x000055d366e64bf1 in luaB_pcall (L=0x7f9514e96208) at lbaselib.c:424
#22 0x000055d366e50df0 in luaD_precall (L=L@entry=0x7f9514e96208, func=func@entry=0x7f9514e01c90, nresults=nresults@entry=2)
at ldo.c:434
#23 0x000055d366e5d02f in luaV_execute (L=L@entry=0x7f9514e96208) at lvm.c:1146
#24 0x000055d366e510bf in luaD_call (L=L@entry=0x7f9514e96208, func=, nResults=) at ldo.c:499
#25 0x000055d366e51111 in luaD_callnoyield (L=0x7f9514e96208, func=, nResults=) at ldo.c:509
#26 0x000055d366e50512 in luaD_rawrunprotected (L=L@entry=0x7f9514e96208, f=f@entry=0x55d366e4ce60 <f_call>,
ud=ud@entry=0x7f95152f5150) at ldo.c:142
#27 0x000055d366e5142d in luaD_pcall (L=L@entry=0x7f9514e96208, func=func@entry=0x55d366e4ce60 <f_call>,
u=u@entry=0x7f95152f5150, old_top=48, ef=) at ldo.c:729
#28 0x000055d366e4e601 in lua_pcallk (L=L@entry=0x7f9514e96208, nargs=nargs@entry=5, nresults=nresults@entry=0,
errfunc=errfunc@entry=1, ctx=ctx@entry=0, k=k@entry=0x0) at lapi.c:969
#29 0x00007f95132e2db8 in _cb (context=0x7f9514ecfd00, ud=0x7f9514e96208, type=3, session=0, source=5, msg=0x7f9512ae79c0,
sz=55) at lualib-src/lua-skynet.c:52
#30 0x000055d366e45a77 in dispatch_message (ctx=0x7f9514ecfd00, msg=0x7f95152f5240) at skynet-src/skynet_server.c:274
---Type to continue, or q to quit---
#31 0x000055d366e46733 in skynet_context_message_dispatch (sm=sm@entry=0x7f9514d08860, q=0x7f9514ed74c0,
weight=weight@entry=-1) at skynet-src/skynet_server.c:334
#32 0x000055d366e46eb5 in thread_worker (p=) at skynet-src/skynet_start.c:162
#33 0x00007f9515150ff8 in ?? () from /lib/ld-musl-x86_64.so.1
#34 0x0000000000000000 in ?? ()

@cloudwu
Copy link
Owner

cloudwu commented Apr 5, 2018

内存问题参考这里: https://github.com/cloudwu/skynet/wiki/MemoryHook

@hanyu363
Copy link
Contributor Author

hanyu363 commented Apr 5, 2018

是被释放了2次
xmalloc: double free in :00000012
Assertion failed: dogtag == MEMORY_ALLOCTAG (skynet-src/malloc_hook.c: clean_prefix: 114)

不知道如何解决这个问题,我分批查看,是发现只要用json序列化,就会触发这个问题。
我这里暂时用sproto来跳过这个问题了,但是不知道为什么会出现。又如何修复。

skynet.register_protocol( {
name = "client",
id = skynet.PTYPE_CLIENT,
unpack = function (msg, sz)
return netpack.tostring(msg, sz)
end,

dispatch = function (session, address, msg)
    event_queue(function ()
        msg = cjson.decode(msg)

        local req_session = msg.session

        local ret_data = {
            result = "success",
            ret_data = {}
        }
        if type(_data) == "string" then
            ret_data.result = _data
        else
            ret_data.ret_data = _data
        end
        logger.Debug("<RESPONSE>", user_info.user_id, req_name, cjson.encode(ret_data))

       -- 里面使用了cjson.encode来把字符串返回给了客户端。
        user_info:ResponseClientData(ret_data, req_session)

        skynet.fork(function ()
            data_manager:Save()
        end)
    end)

end

@cloudwu
Copy link
Owner

cloudwu commented Apr 6, 2018

在真的搞明白你在做什么之前,禁止使用 netpack 这个内部模块的 api 。至少要把 wiki 上的文档读过一遍。不要想当然使用。

@hanyu363
Copy link
Contributor Author

hanyu363 commented Apr 8, 2018

是我使用方式有问题。。感谢帮助。

@hanyu363 hanyu363 closed this as completed Apr 8, 2018
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