Skip to content

Commit

Permalink
Get an old pool in a synchronized block
Browse files Browse the repository at this point in the history
It has race condition if it is placed outside of the block.
  • Loading branch information
tkawachi committed Apr 23, 2014
1 parent 2fdf452 commit 93b1d68
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scalikejdbc-core/src/main/scala/scalikejdbc/ConnectionPool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ object ConnectionPool extends LogSupport {

import scalikejdbc.JDBCUrl._

val oldPoolOpt: Option[ConnectionPool] = pools.get(name)

// register new pool or replace existing pool
pools.synchronized {
val oldPoolOpt: Option[ConnectionPool] = pools.get(name)

// Heroku support
// Heroku support
val pool = url match {
case HerokuPostgresRegexp(_user, _password, _host, _dbname) =>
val _url = "jdbc:postgresql://%s/%s".format(_host, _dbname)
Expand All @@ -108,10 +107,11 @@ object ConnectionPool extends LogSupport {

// wait a little because rarely NPE occurs when immediately accessed.
Thread.sleep(100L)

// asynchronously close the old pool if exists
oldPoolOpt.foreach(pool => abandonOldPool(name, pool))
}

// asynchronously close the old pool if exists
oldPoolOpt.foreach(pool => abandonOldPool(name, pool))
log.debug("Registered connection pool : " + get(name).toString())
}

Expand Down

0 comments on commit 93b1d68

Please sign in to comment.