cloudwu / cloudwu/skynet

sharedata got stack overflow when 100w string key in use

Open
#1,981 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
14.1k
Forks
4.3k
Avg merge
5h 41m
Merged PRs (30d)
1

Description

--examples/sharedata_size.lua
local skynet = require "skynet"
local sharedata = require "skynet.sharedata"

local big_table = {}
local size = 1000000
for i=1,size do
        big_table[tostring(i)] = i
end

skynet.start(function()
        skynet.error("new foobar")
        sharedata.new("foobar", big_table)
end)

跑这个样例的时候会报错StackOverflow

[:01000004] master listen socket 0.0.0.0:2013
[:01000005] LAUNCH snlua cslave
[:01000005] slave connect to master 127.0.0.1:2013
[:01000004] connect from 127.0.0.1:33644 4
[:01000006] LAUNCH harbor 1 16777221
[:01000004] Harbor 1 (fd=4) report 127.0.0.1:2526
[:01000005] Waiting for 0 harbors
[:01000005] Shakehand ready
[:01000007] LAUNCH snlua datacenterd
[:01000008] LAUNCH snlua service_mgr
[:01000009] LAUNCH snlua sharedata_size
[:01000009] Memory warning 32.00 M
[:01000009] Memory warning 64.00 M
[:0100000a] LAUNCH snlua sharedatad
[:01000009] new foobar
[:0100000a] Memory warning 32.00 M
[:0100000a] Memory warning 64.00 M
[:0100000a] lua call [1000009 to :100000a : 3 msgsz = 11757584] error : ./lualib/skynet.lua:988: ./lualib/skynet.lua:452: stack overflow
stack traceback:
        [C]: in function 'skynet.sharedata.core.new'
        ./service/sharedatad.lua:15: in upvalue 'newobj'
        ./service/sharedatad.lua:76: in local 'f'
        ./service/sharedatad.lua:162: in upvalue 'f'
        ./lualib/skynet.lua:402: in function <./lualib/skynet.lua:374>
stack traceback:
        [C]: in function 'assert'
        ./lualib/skynet.lua:988: in function 'skynet.dispatch_message'
[:01000009] init service failed: ./lualib/skynet.lua:720: call failed
stack traceback:
        [C]: in function 'error'
        ./lualib/skynet.lua:720: in upvalue 'yield_call'
        ./lualib/skynet.lua:737: in function 'skynet.call'
        ./lualib/skynet/sharedata.lua:45: in function 'skynet.sharedata.new'
        ./examples/sharedata_size.lua:12: in upvalue 'start'
        ./lualib/skynet.lua:1065: in function <./lualib/skynet.lua:1063>
        [C]: in function 'xpcall'
        ./lualib/skynet.lua:1067: in function 'skynet.init_service'
        ./lualib/skynet.lua:1080: in upvalue 'f'
        ./lualib/skynet.lua:375: in function <./lualib/skynet.lua:374>
[:01000009] KILL self
[:01000002] KILL self

注释掉 lualib-src/lua-sharedata.c:373能好,luaL_checkstack应该在使用lua栈之前用;但是有同学觉得lualib-src/lua-sharedata.c:383的lua_settop会导致栈顶设置异常,大家有什么建议呢?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/sharedata_size.lua and reproduce the stack overflow using the million-string-key table. Then inspect lualib-src/lua-sharedata.c around lines 373 and 383, focusing on luaL_checkstack and lua_settop. Done means the example completes without stack overflow and the sharedata stack handling is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.