#1099154 lua-redis: filedescriptor leak

#1099154#5
Date:
2025-02-28 21:37:20 UTC
From:
To:
Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   not closing connections
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
   * What was the outcome of this action?
   * What outcome did you expect instead?

*** End of the template - remove these template lines ***

#1099154#10
Date:
2025-02-28 22:03:36 UTC
From:
To:
Sorry, I sent the bug report incomplete.

The problem is that the lua-redis package does not close the file
descriptors when calling redis quit or shutdown. Here in this report to the
upstream is the problem explained https://github.com/nrk/redis-lua/issues/71

I detected the problem when running the software kamailio-proxy. After
running some time I got this error

ERROR: app_lua [app_lua_api.c:719]: app_lua_run_ex(): error from Lua:
/usr/share/lua/5.1/redis.lua:813: could not connect to 127.0.0.1:6379 [Too
many open files]

When running a lsof there where a lot of this entries:

kamailio   2205          kamailio    4u     sock                0,8
 0t0      33760 protocol: TCP
kamailio   2205          kamailio   13u     sock                0,8
 0t0      33758 protocol: TCP
kamailio   2205          kamailio   17u     sock                0,8
 0t0     130221 protocol: TCP
kamailio   2205          kamailio   18u     sock                0,8
 0t0     130222 protocol: TCP
kamailio   2205          kamailio   19u     sock                0,8
 0t0     143025 protocol: TCP

To reproduce the problem I wrote a lua script, to use first

ulimit -m 1024
lua pe.lua
...
uccessfully connected and pinged Redis. Total connections: 1018
Successfully connected and pinged Redis. Total connections: 1019
Successfully connected and pinged Redis. Total connections: 1020
Successfully connected and pinged Redis. Total connections: 1021
Error connecting to Redis: /usr/share/lua/5.3/redis.lua:810: could not
connect to 127.0.0.1:6379 [Too many open files]
Reached the maximum open files limit. Sleeping for 10 hours...

The script is:

local redis = require "redis"  -- Ensure this library is installed
(lua-redis)
local socket = require "socket"  -- For sleeping

local redis_host = "127.0.0.1"
local redis_port = 6379

local connection_counter = 0  -- Initialize connection counter
local client_list = {}  -- Initialize an array to store all client
connections