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