Skip to content

Commit

Permalink
feature/throw obp exception earlier, instead of StackOverflowError.
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Sep 18, 2023
1 parent 02a8042 commit aeb995b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions obp-api/src/main/scala/bootstrap/liftweb/CustomDBVendor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bootstrap.liftweb

import java.sql.{Connection, DriverManager}

import net.liftweb.common.{Box, Full, Logger}
import net.liftweb.common.{Box, Failure, Full, Logger}
import net.liftweb.db.ConnectionManager
import net.liftweb.util.ConnectionIdentifier
import net.liftweb.util.Helpers.tryo
Expand Down Expand Up @@ -89,13 +89,16 @@ trait CustomProtoDBVendor extends ConnectionManager {
case Nil =>
val curSize = poolSize
logger.trace("No connection left in pool, waiting...")
wait(50L)
wait(50L*poolSize )
// if we've waited 50 ms and the pool is still empty, temporarily expand it
if (pool.isEmpty && poolSize == curSize && canExpand_?) {
tempMaxSize += 1
logger.debug("Temporarily expanding pool. name=%s, tempMaxSize=%d".format(name, tempMaxSize))
newConnection(name)
}else{
logger.debug(s"The poolSize is expanding to tempMaxSize ($tempMaxSize), we can not create new connection, need to restart OBP now.")
throw new RuntimeException(s"Database may be down, please check database connection! OBP already create $tempMaxSize connections, because all connections are occupied!")
}
newConnection(name)

case x :: xs =>
logger.trace("Found connection in pool, name=%s".format(name))
Expand Down

0 comments on commit aeb995b

Please sign in to comment.