Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential IndexOutOfBoundsException in curActorIsBlocking and concurrentActorCausesBlocking #277

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.jetbrains.kotlinx.lincheck.runner.ExecutionPart.*
import org.jetbrains.kotlinx.lincheck.strategy.*
import org.jetbrains.kotlinx.lincheck.verifier.*
import org.objectweb.asm.*
import java.io.*
import java.lang.reflect.*
import java.util.*
import kotlin.collections.set
Expand Down Expand Up @@ -251,19 +250,25 @@ abstract class ManagedStrategy(
}

private fun failIfObstructionFreedomIsRequired(lazyMessage: () -> String) {
if (testCfg.checkObstructionFreedom && !curActorIsBlocking && !concurrentActorCausesBlocking) {
if (testCfg.checkObstructionFreedom && !currentActorIsBlocking && !concurrentActorCausesBlocking) {
suddenInvocationResult = ObstructionFreedomViolationInvocationResult(lazyMessage())
// Forcibly finish the current execution by throwing an exception.
throw ForcibleExecutionFinishError
}
}

private val curActorIsBlocking: Boolean
get() = scenario.threads[currentThread][currentActorId[currentThread]].blocking
private val currentActorIsBlocking: Boolean
get() {
val actorId = currentActorId[currentThread]
// handle the case when the first actor has not yet started,
// see https://github.com/JetBrains/lincheck/pull/277
if (actorId < 0) return false
return scenario.threads[currentThread][actorId].blocking
}

private val concurrentActorCausesBlocking: Boolean
get() = currentActorId.mapIndexed { iThread, actorId ->
if (iThread != currentThread && !finished[iThread])
if (iThread != currentThread && actorId >= 0 && !finished[iThread])
scenario.threads[iThread][actorId]
else null
}.filterNotNull().any { it.causesBlocking }
Expand Down