openresty / openresty/lua-resty-redis
Connection pool uses connection must be expired
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
We are using lua-resty-redis in high load environment, and encountered unexpected behavior of connection pool.
The webapp server communicates the kvs(Redis) server via the lvs server as below.
WebApp <----> Lvs <----> Kvs
I show summarized lua codes as below.
redis = require 'resty.redis'
client = redis:new()
client:set_timeout(5000)
ok, err = client:connect(kvs_vip, 6379)
...
(keys, set, get, hmget, etc.)
...
client:set_keepalive(895*1000, 100)
Almost of requests are processed normally, but nginx writes error_log like as below sometimes.
... recv() failed (104: Connection reset by peer) ...
I monitored communications between WebApp and Lvs by tcpdump, and found unexpected behavior.
(tcpdump at Lvs)
15:02:55 <- start tcpdump
...
15:48:03.085240
webapp.60060 > kvs_vip.6379: Flags [P.], ... RESP "keys" "foo..."
15:48:03.085283
kvs_vip.6379 > webapp.60060: Flags [R], ...
(tcpdump at WebApp)
15:02:55 <- start tcpdump
...
15:48:03.084994
webapp.60060 > kvs_vip.6379: Flags [P.], ... RESP "keys" "foo..."
15:48:03.085396
kvs_vip.6379 > webapp.60060: Flags [R], ...
I found some packets between webapp.otherport and kvs_vip.6379 in time range from 15:02:55 to 15:48:03, but webapp.60060 and kvs_vip.6379 were not communicating absolutely. So, it seems like nginx used a socket which must be expired and lvs host responded to it by RST packet.
Lvs timeout parameters:
Lvs# ipvsadm -Ln --timeout
Timeout (tcp tcpfin udp): 900 120 300
According to "ipvsadm -Lnc" command log, ip_vs session of webapp.60060 was expired at 15:14:41.
Versions:
nginx-1.14.0
lua-nginx-module-0.10.13
lua-5.1.5
lua-resty-redis-0.26
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported Lua connection flow, especially connect and set_keepalive, and compare it with the LVS timeout output and ipvsadm session-expiration log. Reproduce or trace reuse of the webapp.60060 socket after the LVS entry expires; done means the connection-pool behavior is understood and an actionable fix or confirmed limitation is recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx, redis
- Domain
- backend, databases, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100