Skip to content

Commit b396cd3

Browse files
committed
impl: improve logging around resource cleanup
Another error reported by JetBrains is a `RejectedExecutionException` in the rest api client, and from the stack trace it seems the thread pool in the rest client was at some point shutdown. I think it is some sort of race condition, some thread calling shutting down the rest api client while the UI thread still executes polling and user's action. I tried to reproduce the issue with no success, and so I'm improving the logging around plugin de-initialization in the hope that next time the sequence of events is more helpful.
1 parent 48ed27d commit b396cd3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ class CoderRemoteProvider(
202202
* first page.
203203
*/
204204
private fun logout() {
205+
context.logger.info("Logging out ${client?.me?.username}...")
205206
WorkspaceConnectionManager.reset()
206207
close()
208+
context.logger.info("User ${client?.me?.username} logged out successfully")
207209
}
208210

209211
/**
@@ -244,12 +246,16 @@ class CoderRemoteProvider(
244246
it.cancel()
245247
context.logger.info("Cancelled workspace poll job ${pollJob.toString()}")
246248
}
247-
client?.close()
249+
client?.let {
250+
it.close()
251+
context.logger.info("REST API client closed and resources released")
252+
}
253+
client = null
248254
lastEnvironments.clear()
249255
environments.value = LoadableState.Value(emptyList())
250256
isInitialized.update { false }
251-
client = null
252257
CoderCliSetupWizardState.goToFirstStep()
258+
context.logger.info("Coder plugin is now closed")
253259
}
254260

255261
override val svgIcon: SvgIcon =
@@ -317,12 +323,12 @@ class CoderRemoteProvider(
317323
uri,
318324
shouldDoAutoSetup()
319325
) { restClient, cli ->
320-
// stop polling and de-initialize resources
326+
context.logger.info("Stopping workspace polling and de-initializing resources")
321327
close()
322328
isInitialized.update {
323329
false
324330
}
325-
// start initialization with the new settings
331+
context.logger.info("Starting initialization with the new settings")
326332
this@CoderRemoteProvider.client = restClient
327333
coderHeaderPage.setTitle(context.i18n.pnotr(restClient.url.toString()))
328334

0 commit comments

Comments
 (0)