Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Pooled clients leak a connection per call: pipelines and transactions taken from UnifiedJedis are never closed

未关闭 适合新手
#333 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@ali-jawad 已经在做这个了。

开始于 2026年10月23日。

  • #334 来自 @ali-jawad —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
77/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

阅读 AbstractClient.java 中关于批量和定期入队操作的引用方法,然后阅读 AbstractWorker.java 中关于 worker 故障处理的方法。确认 pipeline 和 transaction 如何获取和关闭,并添加回归测试,使调用次数超过有界池的 maxTotal。完成标准是这些调用将连接归还到池中,且不会耗尽连接池。

由索引模型根据 Issue 内容生成。

描述

Version: jesque 3.0.0 with its jedis 7.2.1. The code is unchanged on master (e4d551d, jedis 8.0.0).

What happens

These calls each take a connection from the client's UnifiedJedis pool and never return it:

  • ClientPoolImpl.batchEnqueue(...), through a pipeline;
  • ClientPoolImpl.recurringEnqueue(...) and ClientPoolImpl.removeRecurringEnqueue(...), through a transaction;
  • WorkerPoolImpl failure handling, through a transaction, when the FailQueueStrategy returns getFailQueueMaxItems(...) > 0.

With a bounded pool, the call after maxTotal such calls fails:

redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object, maxWaitDuration=PT1S
	at redis.clients.jedis.util.Pool.getResource(Pool.java:42)
	...
	at redis.clients.jedis.UnifiedJedis.pipelined(UnifiedJedis.java:6001)
	at redis.clients.jedis.RedisClient.pipelined(RedisClient.java:167)
	at net.greghaines.jesque.client.AbstractClient.doBatchEnqueue(AbstractClient.java:210)

That trace is from master (jedis 8.0.0). In the worker, the exception is caught and logged at WARN, so failures silently stop being recorded. With the default pool config (unbounded, non-blocking), nothing throws. Instead, every call leaves one more connection open on Redis: 50 batch enqueues took CLIENT LIST from 2 to 51 connections.

Why

UnifiedJedis.pipelined() and UnifiedJedis.multi() create the pipeline or transaction on a connection taken from the pool, with closeConnection = true, and only their close() returns it:

https://github.com/redis/jedis/blob/26bbb8e33af4efe569d8b7d1126329e257f79e0b/src/main/java/redis/clients/jedis/UnifiedJedis.java#L5129-L5137
https://github.com/redis/jedis/blob/26bbb8e33af4efe569d8b7d1126329e257f79e0b/src/main/java/redis/clients/jedis/UnifiedJedis.java#L5150-L5158

Jesque calls sync() or exec(), but never close():

In 2.3.0 these calls ran inside PoolUtils.doWorkInPool, which returns the Jedis to the pool, so the leak is new in 3.0.0:

https://github.com/gresrun/jesque/blob/5fbb197fda8319f47f679da4d68c38c1542a9db2/src/main/java/net/greghaines/jesque/client/ClientPoolImpl.java

The non-pooled ClientImpl and WorkerImpl aren't affected: closing a pipeline or transaction of a plain Jedis leaves its connection open.

How to reproduce

  1. Create a pooled client with maxTotal = 3, blockWhenExhausted = true and maxWait = 1s: a JedisPooled on jedis 7.x, or PoolUtils.createJedisPool(config, poolConfig) on master.
  2. Pass it to a ClientPoolImpl.
  3. Call client.batchEnqueue("q", List.of(job)) four times.
  4. The 4th call fails as above, although nothing else uses the pool.

Fix

Close the pipelines and transactions with try-with-resources. AbstractPipeline and AbstractTransaction implement Closeable without a checked exception. I'll open a PR with the fix and regression tests that run more calls than a bounded pool's maxTotal.

Workaround

Subclass ClientPoolImpl, override doBatchEnqueue (and the recurring methods, if you use them), and close the pipeline or transaction there.

主要语言
Java
星标
629
派生
132
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

gresrun/jesque 的其他 Issue

查看 gresrun/jesque 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。