diff --git a/lualib/http/websocket.lua b/lualib/http/websocket.lua index e0ff85c0..8279c7d9 100755 --- a/lualib/http/websocket.lua +++ b/lualib/http/websocket.lua @@ -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)