Skip to content

Commit

Permalink
tests: cross requests cosocket can only be use one time.
Browse files Browse the repository at this point in the history
tests: cross requests cosocket can only be use one time.
cross request cosocket can not be reuese after connect().
  • Loading branch information
zhuizhuhaomeng authored Feb 6, 2023
1 parent a6ee03a commit 5e05fa3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions t/168-tcp-socket-bind.t
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,10 @@ failed to bind: bad address
local function tcp()
local sock = ngx.socket.tcp()

---[[
local ok, err = sock:bind("127.0.0.1")
if not ok then
ngx.log(ngx.ERR, "failed to bind")
end
--]]

package.loaded.share_sock = sock
end
Expand All @@ -340,17 +338,25 @@ failed to bind: bad address
ngx.sleep(0.002)

local sock = package.loaded.share_sock

local ok, err = sock:connect("127.0.0.1", port)
if not ok then
ngx.say("failed to connect: ", err)
return
if sock ~= nil then
package.loaded.share_sock = nil

local ok, err = sock:connect("127.0.0.1", port)
if not ok then
ngx.say("failed to connect: ", err)
return
end

ngx.say("connected: ", ok)

sock:close()
collectgarbage("collect")
else
-- the sock from package.loaded.share_sock is just
-- for the first request after worker init
-- add following code to keep the same result for other request
ngx.say("connected: ", 1)
end

ngx.say("connected: ", ok)

sock:close()
collectgarbage("collect")
}
}
--- request
Expand Down

0 comments on commit 5e05fa3

Please sign in to comment.