lua-nginx-module
lua-nginx-module copied to clipboard
feat: cosocket use mem pool
I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project.
# Why do we need this PR? When we use Cosocket in a long connection, the memory used to establish a new connection at the back end is not immediately freed, causing memory to continue to grow until the long connection is disconnected. Fix this problem by using the pool of new links to free up memory when new links break
The demo will not leak memory
location = /{
content_by_lua_block {
for i = 0, 0xffffffff do
local sock = ngx.socket.tcp()
local ok, err = sock:connect("127.0.0.1", 12345)
if not ok then
ngx.log(ngx.INFO, "failed to connect to peer: ", err)
end
local ok = sock:receive("*l")
assert(ok == "OK")
sock:close()
end
}
}