mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
fix websocket accept mem leakage (#2002)
* fix websocket accept mem leakage * fix websocket accept mem leakage * fix websocket accept mem leakage * fix websocket accept mem leakage
This commit is contained in:
@@ -428,16 +428,25 @@ end
|
|||||||
-- connect / handshake / message / ping / pong / close / error
|
-- connect / handshake / message / ping / pong / close / error
|
||||||
function M.accept(socket_id, handle, protocol, addr, options)
|
function M.accept(socket_id, handle, protocol, addr, options)
|
||||||
if not (options and options.upgrade) then
|
if not (options and options.upgrade) then
|
||||||
socket.start(socket_id)
|
local isok, err = socket.start(socket_id)
|
||||||
|
if not isok then
|
||||||
|
return false, err
|
||||||
|
end
|
||||||
end
|
end
|
||||||
protocol = protocol or "ws"
|
protocol = protocol or "ws"
|
||||||
local ws_obj = _new_server_ws(socket_id, handle, protocol)
|
local ws_obj = _new_server_ws(socket_id, handle, protocol)
|
||||||
ws_obj.addr = addr
|
ws_obj.addr = addr
|
||||||
local on_warning = handle and handle["warning"]
|
local on_warning = handle and handle["warning"]
|
||||||
if on_warning then
|
if on_warning then
|
||||||
socket.warning(socket_id, function (id, sz)
|
local isok = pcall(socket.warning, socket_id, function(id, sz)
|
||||||
on_warning(ws_obj, sz)
|
on_warning(ws_obj, sz)
|
||||||
end)
|
end)
|
||||||
|
if not isok then
|
||||||
|
if not _isws_closed(socket_id) then
|
||||||
|
_close_websocket(ws_obj)
|
||||||
|
end
|
||||||
|
return false, "connect is closed " .. socket_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = xpcall(resolve_accept, debug.traceback, ws_obj, options)
|
local ok, err = xpcall(resolve_accept, debug.traceback, ws_obj, options)
|
||||||
|
|||||||
Reference in New Issue
Block a user