@@ -71,6 +71,7 @@ import java.net.SocketTimeoutException
71
71
import java.net.URL
72
72
import java.net.UnknownHostException
73
73
import java.time.Duration
74
+ import java.util.*
74
75
import javax.net.ssl.SSLHandshakeException
75
76
import javax.swing.Icon
76
77
import javax.swing.JCheckBox
@@ -87,6 +88,7 @@ private const val SESSION_TOKEN = "session-token"
87
88
88
89
class CoderWorkspacesStepView (val setNextButtonEnabled : (Boolean ) -> Unit ) : CoderWorkspacesWizardStep, Disposable {
89
90
private val cs = CoroutineScope (Dispatchers .Main )
91
+ private val jobs: MutableMap <UUID , Job > = mutableMapOf ()
90
92
private var localWizardModel = CoderWorkspacesWizardModel ()
91
93
private val settings: CoderSettingsService = service<CoderSettingsService >()
92
94
@@ -249,7 +251,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
249
251
val c = localWizardModel.client
250
252
if (tableOfWorkspaces.selectedObject != null && c != null ) {
251
253
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
252
- cs.launch {
254
+ jobs[workspace.id]?.cancel()
255
+ jobs[workspace.id] = cs.launch {
253
256
withContext(Dispatchers .IO ) {
254
257
try {
255
258
c.startWorkspace(workspace)
@@ -269,7 +272,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
269
272
val c = localWizardModel.client
270
273
if (tableOfWorkspaces.selectedObject != null && c != null ) {
271
274
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
272
- cs.launch {
275
+ jobs[workspace.id]?.cancel()
276
+ jobs[workspace.id] = cs.launch {
273
277
withContext(Dispatchers .IO ) {
274
278
try {
275
279
// Stop the workspace first if it is running.
@@ -278,7 +282,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
278
282
c.stopWorkspace(workspace)
279
283
loadWorkspaces()
280
284
var elapsed = Duration .ofSeconds(0 )
281
- val timeout = Duration .ofSeconds(1 )
285
+ val timeout = Duration .ofSeconds(5 )
282
286
val maxWait = Duration .ofMinutes(10 )
283
287
while (isActive) { // Wait for the workspace to fully stop.
284
288
delay(timeout.toMillis())
@@ -330,7 +334,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
330
334
val c = localWizardModel.client
331
335
if (tableOfWorkspaces.selectedObject != null && c != null ) {
332
336
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
333
- cs.launch {
337
+ jobs[workspace.id]?.cancel()
338
+ jobs[workspace.id] = cs.launch {
334
339
withContext(Dispatchers .IO ) {
335
340
try {
336
341
c.stopWorkspace(workspace)
@@ -457,6 +462,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
457
462
localWizardModel.cliManager = null
458
463
localWizardModel.client = null
459
464
poller?.cancel()
465
+ jobs.forEach { it.value.cancel() }
460
466
tfUrlComment?.foreground = UIUtil .getContextHelpForeground()
461
467
tfUrlComment?.text = CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connecting" , deploymentURL.host)
462
468
tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connecting" , deploymentURL.host))
@@ -555,6 +561,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
555
561
556
562
private fun triggerWorkspacePolling (fetchNow : Boolean ) {
557
563
poller?.cancel()
564
+ jobs.forEach { it.value.cancel() }
558
565
559
566
poller = cs.launch {
560
567
if (fetchNow) {
@@ -643,6 +650,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
643
650
super .onPrevious()
644
651
logger.info(" Going back to the main view" )
645
652
poller?.cancel()
653
+ jobs.forEach { it.value.cancel() }
646
654
}
647
655
648
656
override fun onNext (wizardModel : CoderWorkspacesWizardModel ): Boolean {
@@ -673,6 +681,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
673
681
configDirectory = cliManager?.coderConfigPath?.toString() ? : " "
674
682
}
675
683
poller?.cancel()
684
+ jobs.forEach { it.value.cancel() }
676
685
677
686
logger.info(" Opening IDE selection window for ${selected.name} " )
678
687
return true
0 commit comments