Skip to content

Fix infinite restart loop when disabled toolkit 2.x cannot be updated… #4523

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

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix infinite restart loop on <=241 when an incompatible version of AWS Toolkit is installed alongside Amazon Q (#4519)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import software.aws.toolkits.jetbrains.AwsToolkit.TOOLKIT_PLUGIN_ID
import software.aws.toolkits.jetbrains.core.plugin.PluginUpdateManager
import software.aws.toolkits.resources.message
import javax.swing.SwingUtilities

class PluginVersionChecker : ApplicationInitializedListener {
override suspend fun execute(asyncScope: CoroutineScope) {
Expand Down Expand Up @@ -51,19 +52,14 @@

// defensively disable the old toolkit if we couldn't update it because we might deadlock during project open
val toolkit = mismatch.firstOrNull { it.id == TOOLKIT_PLUGIN_ID && it.version?.startsWith("2.") == true }
val shouldDisableToolkit = (toolkit != null && updated.none { it == toolkit })
if (shouldDisableToolkit) {
LOG.info { "Attempting to disable aws.toolkit due to known incompatibility" }
val descriptor = toolkit?.descriptor as? IdeaPluginDescriptor

descriptor?.let {
PluginEnabler.getInstance().disable(listOf(descriptor))
} ?: LOG.warn { "Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit?.descriptor}" }
}

if (shouldDisableToolkit || updated.isNotEmpty()) {
if (shouldDisableToolkit(toolkit, updated) || updated.isNotEmpty()) {
LOG.info { "Restarting due to forced update of plugins" }
ApplicationManagerEx.getApplicationEx().restart(true)

// IDE invokeLater is not initialized yet
SwingUtilities.invokeLater {
ApplicationManagerEx.getApplicationEx().restart(true)
}

Check warning on line 62 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L60-L62

Added lines #L60 - L62 were not covered by tests
return
}

Expand Down Expand Up @@ -97,6 +93,26 @@
}
}

private fun shouldDisableToolkit(toolkit: PluginInfo?, updated: List<PluginInfo>): Boolean {
if (toolkit != null && updated.none { it == toolkit }) {
LOG.info { "Attempting to disable aws.toolkit due to known incompatibility" }

Check warning on line 98 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L98

Added line #L98 was not covered by tests
val descriptor = toolkit.descriptor as? IdeaPluginDescriptor ?: run {
LOG.warn { "Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit.descriptor}" }
return false

Check warning on line 101 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L100-L101

Added lines #L100 - L101 were not covered by tests
}

if (!descriptor.isEnabled) {
LOG.info { "Does not need to disable toolkit since it is already disabled" }
return false

Check warning on line 106 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L105-L106

Added lines #L105 - L106 were not covered by tests
}

PluginEnabler.getInstance().disable(listOf(descriptor))
return true

Check warning on line 110 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L109-L110

Added lines #L109 - L110 were not covered by tests
}

return false

Check warning on line 113 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt

View check run for this annotation

Codecov / codecov/patch

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt#L113

Added line #L113 was not covered by tests
}

companion object {
private val LOG = getLogger<PluginVersionChecker>()
}
Expand Down
Loading