pool icon indicating copy to clipboard operation
pool copied to clipboard

🚌 A golang general network connection poolction pool

Results 12 pool issues
Sort by recently updated
recently updated
newest added

假如连接池初始化后,连接的服务方关闭了,连接池中的所有连接就失效了。 因此,每次调用 Get 方法获取连接池中的一个连接时,需要类似 ping 的检查,失效的时候重新创建连接。 建议: 初始化的时候提供一个 Ping 方法,类似 factory close 的。

enhancement

Put(conn interface{}) 这方法里 c.mu.Lock()后为什么不直接 defer c.mu.Unlock() 而是各个select 分支上再 c.mu.Unlock() 有什么特殊的考虑吗?

请问下 pool 为什么每次要 lock ,是什么考虑呢 // getConns 获取所有连接 func (c *channelPool) getConns() chan *idleConn { c.mu.Lock() conns := c.conns c.mu.Unlock()

修改了一个版本来修复hang的问题,参考了golang db connection pool的逻辑来处理意外hang的情况,我再自己的程序里面用了一段时间(半个月左右),暂时没有遇到问题。

## 现象: 当有较多的goroutine在等待从Pool中Get连接,同时没有空闲连接时,有种情况,当被使用的连接,同时出错并被调用者Close掉时,等待获取连接的goroutine会一直阻塞等待从connReq这个channel获取连接,而所有的连接都已经被关闭了,不会再有可用的连接,导致一直等待,程序hang住。 ## 原因 在`Get`方法中,第133行检查完已创建的连接数达到了最大值后,会等待从`connReq`的channel等待其它goroutine Put回来的连接。 在`Close`方法中,会把`openingConns--`,但已经没法触发`Get`方法去新建连接了,`Get`方法都被阻塞在从`connReq`的channel拿连接了。 Get方法133行 https://github.com/silenceper/pool/blob/58e025e48bf97061c9f2638564fd6857092caeb4/channel.go#L133 https://github.com/silenceper/pool/blob/58e025e48bf97061c9f2638564fd6857092caeb4/channel.go#L130-L140 Close方法 https://github.com/silenceper/pool/blob/58e025e48bf97061c9f2638564fd6857092caeb4/channel.go#L202-L213

enhancement

https://github.com/silenceper/pool/blob/1f4530b6ba1730216c69abdd58f6e35e51636cad/channel.go#L149 在Put方法中,如果发现连接池是满的,这时候是否可以把老的连接删除,把新的连接加进来? 这样可以实时更新连接池了吧 @silenceper @hopehook

type channelPool struct { mu sync.RWMutex conns chan *idleConn factory func() (interface{}, error) close func(interface{}) error ping func(interface{}) error idleTimeout, waitTimeOut time.Duration maxActive int openingConns int connReqs []chan connReq }...

## Feat add github workflow ci ## Fix The reason for ci block can be found in https://github.com/silenceper/pool/issues/38 `ErrMaxActiveConnReached` is hard to reproduce, So I delete the test case for...