Skip to content

Commit

Permalink
Allow connecting when lifecycle is created
Browse files Browse the repository at this point in the history
If the agent status is "connected" but the lifecycle state is "created",
still allow connecting.

Fixes #450.
  • Loading branch information
code-asher committed Jul 9, 2024
1 parent 1ea0cb8 commit f59bd1f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

## Unreleased

### Changed

- Allow connecting when the agent state is "connected" but the lifecycle state
is "created". This may resolve issues when trying to connect to an updated
workspace where the agent has restarted but lifecycle scripts have not been
ran again.

## 2.12.0 - 2024-07-02

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup=com.coder.gateway
# Zip file name.
pluginName=coder-gateway
# SemVer format -> https://semver.org
pluginVersion=2.12.0
pluginVersion=2.12.1
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=233.6745
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class WorkspaceAndAgentStatus(val icon: Icon, val label: String, val descri
fun statusColor(): JBColor =
when (this) {
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
}
Expand All @@ -63,15 +63,21 @@ enum class WorkspaceAndAgentStatus(val icon: Icon, val label: String, val descri
* Return true if the agent is in a connectable state.
*/
fun ready(): Boolean {
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY)
// It seems that the agent can get stuck in a `created` state if the
// workspace is updated and the agent is restarted (presumably because
// lifecycle scripts are not running again). This feels like either a
// Coder or template bug, but `coder ssh` and the VS Code plugin will
// still connect so do the same here to not be the odd one out.
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY, CREATED)
.contains(this)
}

/**
* Return true if the agent might soon be in a connectable state.
*/
fun pending(): Boolean {
return listOf(CONNECTING, TIMEOUT, CREATED, AGENT_STARTING, START_TIMEOUT)
// See ready() for why `CREATED` is not in this list.
return listOf(CONNECTING, TIMEOUT, AGENT_STARTING, START_TIMEOUT)
.contains(this)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/coder/gateway/util/LinkHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ fun handleLink(
if (status.pending()) {
// TODO: Wait for the agent to be ready.
throw IllegalArgumentException(
"The agent \"${agent.name}\" is ${status.toString().lowercase()}; please wait then try again",
"The agent \"${agent.name}\" has a status of \"${status.toString().lowercase()}\"; please wait then try again",
)
} else if (!status.ready()) {
throw IllegalArgumentException("The agent \"${agent.name}\" is ${status.toString().lowercase()}; unable to connect")
throw IllegalArgumentException("The agent \"${agent.name}\" has a status of \"${status.toString().lowercase()}\"; unable to connect")
}

val cli =
Expand Down

0 comments on commit f59bd1f

Please sign in to comment.