Skip to content

Commit efefd3e

Browse files
committed
fix: don't wait too long to connect to host
- remote host connection handshake never finishes when Coder agent is down. - this fix caps the handshake to 30seconds
1 parent 1051381 commit efefd3e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.Disposer
2323
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
2424
import com.intellij.remote.AuthType
2525
import com.intellij.remote.RemoteCredentialsHolder
26+
import com.intellij.ssh.SshException
2627
import com.intellij.ui.AnimatedIcon
2728
import com.intellij.ui.ColoredListCellRenderer
2829
import com.intellij.ui.DocumentAdapter
@@ -49,14 +50,17 @@ import kotlinx.coroutines.CancellationException
4950
import kotlinx.coroutines.CoroutineScope
5051
import kotlinx.coroutines.Dispatchers
5152
import kotlinx.coroutines.Job
53+
import kotlinx.coroutines.TimeoutCancellationException
5254
import kotlinx.coroutines.async
5355
import kotlinx.coroutines.cancel
5456
import kotlinx.coroutines.cancelAndJoin
5557
import kotlinx.coroutines.launch
5658
import kotlinx.coroutines.runBlocking
59+
import kotlinx.coroutines.time.withTimeout
5760
import kotlinx.coroutines.withContext
5861
import java.awt.Component
5962
import java.awt.FlowLayout
63+
import java.time.Duration
6064
import java.util.Locale
6165
import javax.swing.ComboBoxModel
6266
import javax.swing.DefaultComboBoxModel
@@ -134,7 +138,7 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
134138

135139
ideResolvingJob = cs.launch {
136140
try {
137-
val executor = withContext(Dispatchers.IO) { createRemoteExecutor() }
141+
val executor = withTimeout(Duration.ofSeconds(30)) { createRemoteExecutor() }
138142
retrieveIDES(executor, selectedWorkspace)
139143
if (ComponentValidator.getInstance(tfProject).isEmpty) {
140144
installRemotePathValidator(executor)
@@ -143,6 +147,21 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
143147
when (e) {
144148
is InterruptedException -> Unit
145149
is CancellationException -> Unit
150+
is TimeoutCancellationException,
151+
is SshException -> {
152+
logger.error("Can't connect to workspace ${selectedWorkspace.name}. Reason: $e")
153+
withContext(Dispatchers.Main) {
154+
disableNextAction()
155+
cbIDE.renderer = object : ColoredListCellRenderer<IdeWithStatus>() {
156+
override fun customizeCellRenderer(list: JList<out IdeWithStatus>, value: IdeWithStatus?, index: Int, isSelected: Boolean, cellHasFocus: Boolean) {
157+
background = UIUtil.getListBackground(isSelected, cellHasFocus)
158+
icon = UIUtil.getBalloonErrorIcon()
159+
append("Can't connect to the workspace. Please make sure Coder Agent is running!")
160+
}
161+
}
162+
}
163+
}
164+
146165
else -> {
147166
logger.error("Could not resolve any IDE for workspace ${selectedWorkspace.name}. Reason: $e")
148167
withContext(Dispatchers.Main) {

0 commit comments

Comments
 (0)