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

可以帮忙看一下这个Segmentation fault 吗 #923

Closed
sendysucc opened this issue Dec 20, 2018 · 1 comment
Closed

可以帮忙看一下这个Segmentation fault 吗 #923

sendysucc opened this issue Dec 20, 2018 · 1 comment

Comments

@sendysucc
Copy link

自己写的一个websocket的 C 服务, echo回去客户端发送的消息:

客户端在for循环中,不断给websocket的c服务发送 "hello world" , 每次服务端echo 回去 3000多次的时候,就会出现 segmentation fault . 设置 c服务的 分配内存并发送socket消息,然后释放内存部分的代码:
`frm = skynet_malloc(hsize+ sz);
memset(frm,0, hsize + sz);
memcpy(frm,buf,hsize);

memcpy(frm + hsize , buffer, sz);
skynet_socket_send(wb->ctx, id , (void *)frm, hsize+ sz );
skynet_free(frm);`

dump:

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <https://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./skynet...done. [New LWP 30023] [New LWP 30019] [New LWP 30020] [New LWP 30021] [New LWP 30022] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by ./skynet ./examples/config.websocket'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000004797ba in je_extent_heap_remove (ph=ph@entry=0x7fb3ade02660, phn=phn@entry=0x7fb3ade06fc0) at src/extent.c:278
278 ph_gen(, extent_heap_, extent_heap_t, extent_t, ph_link, extent_snad_comp)
[Current thread is 1 (Thread 0x7fb3aaff6700 (LWP 30023))]
(gdb) bt
#0 0x00000000004797ba in je_extent_heap_remove (ph=ph@entry=0x7fb3ade02660, phn=phn@entry=0x7fb3ade06fc0) at src/extent.c:278
#1 0x000000000047c1b5 in extents_remove_locked (tsdn=0x7fb3ade02cc8, extent=0x7fb3ade06fc0, extents=0x7fb3ade025f8)
at src/extent.c:342
#2 je_extents_evict (tsdn=tsdn@entry=0x7fb3aaff4f00, arena=arena@entry=0x7fb3ade00980,
r_extent_hooks=r_extent_hooks@entry=0x7fb3aaff3d30, extents=extents@entry=0x7fb3ade025f8, npages_min=npages_min@entry=5692)
at src/extent.c:557
#3 0x0000000000441598 in arena_stash_decayed (decay_extents=, npages_decay_max=1, npages_limit=5692,
extents=0x7fb3ade025f8, r_extent_hooks=0x7fb3aaff3d30, arena=0x7fb3ade00980, tsdn=0x7fb3aaff4f00) at src/arena.c:733
#4 arena_decay_to_limit (tsdn=tsdn@entry=0x7fb3aaff4f00, arena=arena@entry=0x7fb3ade00980, decay=decay@entry=0x7fb3ade03a98,
extents=extents@entry=0x7fb3ade025f8, all=all@entry=false, npages_limit=5692, npages_decay_max=1, is_background_thread=false)
at src/arena.c:834
#5 0x0000000000441aa6 in arena_decay_to_limit (is_background_thread=, npages_decay_max=,
npages_limit=, all=, extents=, decay=, arena=,
tsdn=) at src/arena.c:823
#6 arena_decay_try_purge (is_background_thread=, npages_limit=, current_npages=,
extents=, decay=, arena=, tsdn=) at src/arena.c:515
#7 arena_maybe_decay (tsdn=tsdn@entry=0x7fb3aaff4f00, arena=arena@entry=0x7fb3ade00980, decay=decay@entry=0x7fb3ade03a98,
extents=extents@entry=0x7fb3ade025f8, is_background_thread=is_background_thread@entry=false) at src/arena.c:662
#8 0x0000000000444258 in arena_maybe_decay (is_background_thread=false, extents=0x7fb3ade025f8, decay=0x7fb3ade03a98,
arena=0x7fb3ade00980, tsdn=0x7fb3aaff4f00) at src/arena.c:620
#9 arena_decay_impl (all=false, is_background_thread=false, extents=0x7fb3ade025f8, decay=0x7fb3ade03a98, arena=0x7fb3ade00980,
tsdn=0x7fb3aaff4f00) at src/arena.c:864
#10 arena_decay_dirty (all=false, is_background_thread=false, arena=0x7fb3ade00980, tsdn=0x7fb3aaff4f00) at src/arena.c:885
#11 je_arena_decay (tsdn=0x7fb3aaff4f00, arena=0x7fb3ade00980, is_background_thread=false, all=false) at src/arena.c:898
#12 0x00000000004a659c in arena_decay_ticks (nticks=100, arena=, tsdn=)
at include/jemalloc/internal/arena_inlines_b.h:74
#13 je_tcache_bin_flush_small (tsd=tsd@entry=0x7fb3aaff4f00, tcache=tcache@entry=0x7fb3aaff50c0, tbin=tbin@entry=0x7fb3aaff5100,
binind=binind@entry=2, rem=100) at src/tcache.c:164
#14 0x000000000043c9da in tcache_dalloc_small (slow_path=false, binind=2, ptr=0x7fb3adc091e0, tcache=,
tsd=) at include/jemalloc/internal/tcache_inlines.h:178
#15 arena_dalloc (slow_path=false, alloc_ctx=, tcache=, ptr=0x7fb3adc091e0, tsdn=)
at include/jemalloc/internal/arena_inlines_b.h:224
#16 idalloctm (slow_path=false, is_internal=false, alloc_ctx=, tcache=, ptr=0x7fb3adc091e0,
tsdn=) at include/jemalloc/internal/jemalloc_internal_inlines_c.h:118
#17 ifree (slow_path=false, tcache=, ptr=0x7fb3adc091e0, tsd=0x7fb3aaff4f00) at src/jemalloc.c:2222
#18 je_free (ptr=0x7fb3adc091e0) at src/jemalloc.c:2393
#19 0x0000000000413960 in free (ptr=0x7fb3adc091e0) at skynet-src/malloc_hook.c:188
#20 0x00007fb3aa1cd7c0 in build_frame (wb=0x7fb3adda3230, id=2, opcode=1 '\001', buffer=0x7fb3adc4b6e0, sz=12)
at service-src/service_websocket.c:766
#21 0x00007fb3aa1cd5ca in handle_message_data (wb=0x7fb3adda3230, c=0x7fb3addb33e0, id=2, buffer=0x7fb3add87c20, sz=18)
at service-src/service_websocket.c:703
#22 0x00007fb3aa1cbe3b in handle_socket_data (wb=0x7fb3adda3230, c=0x7fb3addb33e0, id=2, buffer=0x7fb3add87c20, sz=18)
at service-src/service_websocket.c:313
#23 0x00007fb3aa1cbd4d in dispatch_socket_message (wb=0x7fb3adda3230, msg=0x7fb3adcf8160, sz=0)
at service-src/service_websocket.c:276
#24 0x00007fb3aa1cbb8c in _cb (ctx=0x7fb3add76d80, ud=0x7fb3adda3230, type=6, session=0, source=0, msg=0x7fb3adcf8160, sz=24)
at service-src/service_websocket.c:238
#25 0x000000000040a41a in dispatch_message (ctx=0x7fb3add76d80, msg=0x7fb3aaff46e0) at skynet-src/skynet_server.c:274
#26 0x000000000040a673 in skynet_context_message_dispatch (sm=0x7fb3adc097e0, q=0x7fb3addade80, weight=-1)
at skynet-src/skynet_server.c:334
#27 0x000000000040bf20 in thread_worker (p=0x7ffee2b18680) at skynet-src/skynet_start.c:163
#28 0x00007fb3aeb656ba in start_thread (arg=0x7fb3aaff6700) at pthread_create.c:333
#29 0x00007fb3ae18641d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb)
`

@cloudwu
Copy link
Owner

cloudwu commented Dec 20, 2018

  1. skynet_socket_send 后不要 free
  2. 不建议写任何 c 服务。

@cloudwu cloudwu closed this as completed Dec 20, 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