Skip to content

Commit

Permalink
Prevent modifying the concurrency limit of the thread pools underlyin…
Browse files Browse the repository at this point in the history
…g locked code thunks (#240)
  • Loading branch information
Masuzu authored Feb 27, 2018
1 parent ce09a82 commit 0730ba4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/src/main/scala/com/criteo/cuttle/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ case class Execution[S <: Scheduling](
*
* While waiting for the lock, the [[Execution]] will be seen as __WAITING__ in the UI and the API.
*/
def withMaxParallelRuns[A, B](lock: A, concurrencyLimit: Int)(thunk: => Future[B]) = {
def withMaxParallelRuns[A, B](lock: A, concurrencyLimit: Int)(thunk: => Future[B]): Future[B] = {
if (isWaiting.get) {
sys.error(s"Already waiting")
} else {
Expand All @@ -254,7 +254,11 @@ case class Execution[S <: Scheduling](
}
Execution.locks(lock)
}
pool.run(this, s"Locked on ${lock}") { () =>
require(
pool.concurrencyLimit == concurrencyLimit,
s"Inconsistent concurrency limits defined for the execution pool for $lock"
)
pool.run(this, s"Locked on $lock") { () =>
streams.debug(s"Resuming")
isWaiting.set(false)
thunk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.circe.syntax._
*
* @param concurrencyLimit The maximum number of concurrent executions.
*/
class ExecutionPool(concurrencyLimit: Int) extends WaitingExecutionQueue {
case class ExecutionPool(concurrencyLimit: Int) extends WaitingExecutionQueue {
def canRunNextCondition(implicit txn: InTxn) = _running().size < concurrencyLimit
def doRunNext()(implicit txn: InTxn): Unit = ()

Expand Down

0 comments on commit 0730ba4

Please sign in to comment.