Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- no longer spam Toolbox with requests to establish the SSH connections every 5 seconds

## 0.8.1 - 2025-12-11

### Changed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=0.8.1
version=0.8.2
group=com.coder.toolbox
name=coder-toolbox
7 changes: 3 additions & 4 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CoderRemoteEnvironment(

init {
if (context.settingsStore.shouldAutoConnect(id)) {
context.logger.info("resuming SSH connection to $id — last session was still active.")
context.logger.info("Last session to $id was still active, trying to establish SSH connection")
startSshConnection()
}
refreshAvailableActions()
Expand Down Expand Up @@ -308,14 +308,13 @@ class CoderRemoteEnvironment(
*
* Returns true if the SSH connection was scheduled to start, false otherwise.
*/
fun startSshConnection(): Boolean {
fun startSshConnection() {
if (environmentStatus.ready() && !isConnected.value) {
connectionRequest.update {
true
}
return true
context.logger.info("Workspace status is ready and there is no existing connection, resuming SSH connection to $id")
}
return false
}

override val deleteActionFlow: StateFlow<(() -> Unit)?> = MutableStateFlow(null)
Expand Down
34 changes: 8 additions & 26 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ class CoderRemoteProvider(
// different information?
it.name
}?.map { agent ->
// If we have an environment already, update that.
val env = CoderRemoteEnvironment(context, client, cli, ws, agent)
lastEnvironments.firstOrNull { it == env }?.let {
it.update(ws, agent)
it
} ?: env
lastEnvironments.firstOrNull { it.id == "${ws.name}.${agent.name}" }
?.also {
// If we have an environment already, update that.
it.update(ws, agent)
} ?: CoderRemoteEnvironment(context, client, cli, ws, agent)
} ?: emptyList()
}
}.toSet()
}.toSet().sortedBy { it.id }

// In case we logged out while running the query.
if (!isActive) {
Expand All @@ -153,7 +152,7 @@ class CoderRemoteProvider(
}

environments.update {
LoadableState.Value(resolvedEnvironments.toList())
LoadableState.Value(resolvedEnvironments)
}
if (!isInitialized.value) {
context.logger.info("Environments for ${client.url} are now initialized")
Expand All @@ -163,23 +162,8 @@ class CoderRemoteProvider(
}
lastEnvironments.apply {
clear()
addAll(resolvedEnvironments.sortedBy { it.id })
addAll(resolvedEnvironments)
}

if (WorkspaceConnectionManager.shouldEstablishWorkspaceConnections) {
WorkspaceConnectionManager.allConnected().forEach { wsId ->
val env = lastEnvironments.firstOrNull() { it.id == wsId }
if (env != null && !env.isConnected()) {
context.logger.info("Establishing lost SSH connection for workspace with id $wsId")
if (!env.startSshConnection()) {
context.logger.info("Can't establish lost SSH connection for workspace with id $wsId")
}
}
}
WorkspaceConnectionManager.reset()
}

WorkspaceConnectionManager.collectStatuses(lastEnvironments)
} catch (_: CancellationException) {
context.logger.debug("${client.url} polling loop canceled")
break
Expand All @@ -190,7 +174,6 @@ class CoderRemoteProvider(
} else {
context.logger.error(ex, "workspace polling error encountered")
if (ex is APIResponseException && ex.isTokenExpired) {
WorkspaceConnectionManager.shouldEstablishWorkspaceConnections = true
close()
context.envPageManager.showPluginEnvironmentsPage()
errorBuffer.add(ex)
Expand Down Expand Up @@ -225,7 +208,6 @@ class CoderRemoteProvider(
*/
private fun logout() {
context.logger.info("Logging out ${client?.me?.username}...")
WorkspaceConnectionManager.reset()
close()
context.logger.info("User ${client?.me?.username} logged out successfully")
}
Expand Down
22 changes: 0 additions & 22 deletions src/main/kotlin/com/coder/toolbox/WorkspaceConnectionManager.kt

This file was deleted.

Loading