()
| 227 | } |
| 228 | |
| 229 | func (pool *Pool) newConnectionProducer() { |
| 230 | var connection Connection |
| 231 | var err error |
| 232 | |
| 233 | for { |
| 234 | connection.conn = nil |
| 235 | |
| 236 | pool.synchro.Lock() |
| 237 | |
| 238 | connection = pool.getIdleConnectionUnsafe() |
| 239 | if connection.conn == nil { |
| 240 | if pool.synchro.stats.TotalCount >= pool.maxAlive { |
| 241 | // Can't create more connections |
| 242 | pool.synchro.Unlock() |
| 243 | time.Sleep(10 * time.Millisecond) |
| 244 | continue |
| 245 | } |
| 246 | pool.synchro.stats.TotalCount++ // "Reserving" new connection |
| 247 | } |
| 248 | |
| 249 | pool.synchro.Unlock() |
| 250 | |
| 251 | if connection.conn == nil { |
| 252 | connection, err = pool.createNewConnection() |
| 253 | if err != nil { |
| 254 | pool.synchro.Lock() |
| 255 | pool.synchro.stats.TotalCount-- // Bad luck, should try again |
| 256 | pool.synchro.Unlock() |
| 257 | |
| 258 | time.Sleep(time.Duration(10+rand.Intn(90)) * time.Millisecond) |
| 259 | continue |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | pool.readyConnection <- connection |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | func (pool *Pool) createNewConnection() (Connection, error) { |
| 268 | var connection Connection |
no test coverage detected