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

websocket.lua使用时遇到的一个错误 #1717

Open
world100 opened this issue Mar 17, 2023 · 4 comments
Open

websocket.lua使用时遇到的一个错误 #1717

world100 opened this issue Mar 17, 2023 · 4 comments

Comments

@world100
Copy link

[:00000014] [error][.watchdog.service][2023-03-15 19:35:17] <@../src/ndgame/watchdog/handler.lua:310>
websocket.accept err ../depends/skynet/lualib/http/websocket.lua:82: assertion failed!
stack traceback:
[C]: in function 'assert'
../depends/skynet/lualib/http/websocket.lua:82: in upvalue 'read_handshake'
../depends/skynet/lualib/http/websocket.lua:254: in function <../depends/skynet/lualib/http/websocket.lua:252>
[C]: in function 'xpcall'
../depends/skynet/lualib/http/websocket.lua:412: in function 'http.websocket.accept'
../src/ndgame/watchdog/handler.lua:307: in function 'watchdog.handler.wsData'
[C]: in function 'skynet.pcall'
../src/common/base/class.lua:15: in function <../src/common/base/class.lua:10>
[C]: in function 'xpcall'
../src/common/base/dispatch.lua:61: in function 'dispatch.dispatchMessage'
[C]: in function 'skynet.pcall'
../src/common/base/class.lua:15: in upvalue 'f'
../depends/skynet/lualib/skynet.lua:281: in function <../depends/skynet/lualib/skynet.lua:253>

客户端长时间挂着,会出现这个问题

我现在的修改是这样:
local function resolve_accept(self, options)
try_handle(self, "connect")
local ok, code, err, url = pcall(read_handshake, self, options and options.upgrade)
--这里增加报错后处理
if not ok then
try_handle(self, "close")
return
end

不知道大家有没有遇到过

@world100
Copy link
Author

1.5, 1.6 版本都存在这个问题
原码中是这样的
image

@cloudwu
Copy link
Owner

cloudwu commented Mar 17, 2023

cc @lvzixun

@cloudwu
Copy link
Owner

cloudwu commented Dec 12, 2023

或许和 #1838 是类似问题。

@mengtianci
Copy link

mengtianci commented Jul 18, 2024

我是这样预防的。。(主要是不想去魔改底层代码)
local ok, errmsg = websocket.accept(fd, handler, protocol, addr)
if not ok then
skynet.error(string.format("websocket.accept (fd: %s) returns error: %s", fd, errmsg))
websocket.close(fd) -- 这里不一定直接关闭fd,可以回调到业务层之后的某个地方再处理
end

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

3 participants