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:
华仔
2024-12-07 15:20:19 +08:00
committed by GitHub
parent 4c8d42153e
commit 2fc8e86925

View File

@@ -428,16 +428,25 @@ end
-- connect / handshake / message / ping / pong / close / error
function M.accept(socket_id, handle, protocol, addr, options)
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
protocol = protocol or "ws"
local ws_obj = _new_server_ws(socket_id, handle, protocol)
ws_obj.addr = addr
local on_warning = handle and handle["warning"]
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)
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
local ok, err = xpcall(resolve_accept, debug.traceback, ws_obj, options)