Skip to content

Commit

Permalink
fix(queue): NPE on RunTaskHandler on startTime (#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Mar 1, 2018
1 parent f961e71 commit bad0b55
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,37 +175,41 @@ class RunTaskHandler(
private fun Task.checkForTaskTimeout(taskModel: com.netflix.spinnaker.orca.pipeline.model.Task, stage: Stage, message: Message) {
if (this is RetryableTask) {
val startTime = taskModel.startTime.toInstant()
val pausedDuration = stage.execution.pausedDurationRelativeTo(startTime)
val elapsedTime = Duration.between(startTime, clock.instant())
val throttleTime = message.getAttribute<TotalThrottleTimeAttribute>()?.totalThrottleTimeMs ?: 0
val actualTimeout = (
if (this is OverridableTimeoutRetryableTask && stage.parentWithTimeout.isPresent)
stage.parentWithTimeout.get().timeout.get().toDuration()
else
timeout.toDuration()
)
if (elapsedTime.minus(pausedDuration).minusMillis(throttleTime) > actualTimeout) {
val durationString = formatTimeout(elapsedTime.toMillis())
val msg = StringBuilder("${javaClass.simpleName} of stage ${stage.name} timed out after $durationString. ")
msg.append("pausedDuration: ${formatTimeout(pausedDuration.toMillis())}, ")
msg.append("throttleTime: ${formatTimeout(throttleTime)}, ")
msg.append("elapsedTime: ${formatTimeout(elapsedTime.toMillis())},")
msg.append("timeoutValue: ${formatTimeout(actualTimeout.toMillis())}")

log.warn(msg.toString())
throw TimeoutException(msg.toString())
if (startTime != null) {
val pausedDuration = stage.execution.pausedDurationRelativeTo(startTime)
val elapsedTime = Duration.between(startTime, clock.instant())
val throttleTime = message.getAttribute<TotalThrottleTimeAttribute>()?.totalThrottleTimeMs ?: 0
val actualTimeout = (
if (this is OverridableTimeoutRetryableTask && stage.parentWithTimeout.isPresent)
stage.parentWithTimeout.get().timeout.get().toDuration()
else
timeout.toDuration()
)
if (elapsedTime.minus(pausedDuration).minusMillis(throttleTime) > actualTimeout) {
val durationString = formatTimeout(elapsedTime.toMillis())
val msg = StringBuilder("${javaClass.simpleName} of stage ${stage.name} timed out after $durationString. ")
msg.append("pausedDuration: ${formatTimeout(pausedDuration.toMillis())}, ")
msg.append("throttleTime: ${formatTimeout(throttleTime)}, ")
msg.append("elapsedTime: ${formatTimeout(elapsedTime.toMillis())},")
msg.append("timeoutValue: ${formatTimeout(actualTimeout.toMillis())}")

log.warn(msg.toString())
throw TimeoutException(msg.toString())
}
}
}
}

private fun checkForStageTimeout(stage: Stage) {
stage.parentWithTimeout.ifPresent {
val startTime = it.startTime.toInstant()
val elapsedTime = Duration.between(startTime, clock.instant())
val pausedDuration = stage.execution.pausedDurationRelativeTo(startTime)
val timeout = Duration.ofMillis(it.timeout.get())
if (elapsedTime.minus(pausedDuration) > timeout) {
throw TimeoutException("Stage ${stage.name} timed out after ${formatTimeout(elapsedTime.toMillis())}")
if (startTime != null) {
val elapsedTime = Duration.between(startTime, clock.instant())
val pausedDuration = stage.execution.pausedDurationRelativeTo(startTime)
val timeout = Duration.ofMillis(it.timeout.get())
if (elapsedTime.minus(pausedDuration) > timeout) {
throw TimeoutException("Stage ${stage.name} timed out after ${formatTimeout(elapsedTime.toMillis())}")
}
}
}
}
Expand Down

0 comments on commit bad0b55

Please sign in to comment.