Skip to content

Commit d9be189

Browse files
committed
fix: transparently propagate error message when monkey patching TCP
socket metatable.
1 parent 759160e commit d9be189

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/resty/core/socket_tcp.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ local error = error
1414
local assert = assert
1515
local getmetatable = getmetatable
1616
local type = type
17+
local pcall = pcall
1718
local select = select
1819
local co_yield = coroutine._yield
1920
local table_new = require("table.new")
@@ -172,7 +173,11 @@ do
172173
local old_socket_tcp = ngx.socket.tcp
173174

174175
function ngx.socket.tcp()
175-
local sock = old_socket_tcp()
176+
local ok, sock = pcall(old_socket_tcp)
177+
if not ok then
178+
error(sock, 2)
179+
end
180+
176181
local mt = getmetatable(sock)
177182

178183
mt.tlshandshake = tlshandshake

0 commit comments

Comments
 (0)