diff --git a/lualib/http/websocket.lua b/lualib/http/websocket.lua index 431fc0ec..163d3d8b 100755 --- a/lualib/http/websocket.lua +++ b/lualib/http/websocket.lua @@ -14,6 +14,7 @@ local pairs = pairs local error = error local string = string local xpcall = xpcall +local pcall = pcall local debug = debug local table = table local tonumber = tonumber @@ -481,7 +482,12 @@ function M.connect(url, header, timeout) local socket_id = sockethelper.connect(host_addr, host_port, timeout) local ws_obj = _new_client_ws(socket_id, protocol, hostname) ws_obj.addr = host - write_handshake(ws_obj, host_addr, uri, header) + + local is_ok,err = pcall(write_handshake, ws_obj, host_addr, uri, header) + if not is_ok then + _close_websocket(ws_obj) + error(err) + end return socket_id end