User: joe Date: 16 Nov 25 08:13 Revision: 8740f0a1cb0e5ff4309dcd1284293061d76c4e83 Summary: Fix deadlock in TemplateProvider. Closes #2542 TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10295&personal=false Index: src/main/kotlin/creator/custom/providers/TemplateProvider.kt =================================================================== --- src/main/kotlin/creator/custom/providers/TemplateProvider.kt (revision fa06b3b02e9e5e1c8f69cb1042e894402da7fadb) +++ src/main/kotlin/creator/custom/providers/TemplateProvider.kt (revision 8740f0a1cb0e5ff4309dcd1284293061d76c4e83) @@ -82,34 +82,38 @@ bundle: ResourceBundle? = null ): List { val bundle = bundle ?: loadMessagesBundle(modalityState, repoRoot) + val templatesToLoad = mutableListOf() val visitor = object : VirtualFileVisitor() { override fun visitFile(file: VirtualFile): Boolean { if (!file.isFile || !file.name.endsWith(".mcdev.template.json")) { return true } - runBlocking(Dispatchers.Unconfined) { + templatesToLoad += file + + return true + } + } + VfsUtilCore.visitChildrenRecursively(repoRoot, visitor) + + for (file in templatesToLoad) { - try { - createVfsLoadedTemplate(modalityState, file.parent, file, bundle = bundle) - ?.let(templates::add) - } catch (t: Throwable) { - if (t is ControlFlowException) { - throw t - } + try { + createVfsLoadedTemplate(modalityState, file.parent, file, bundle = bundle) + ?.let(templates::add) + } catch (t: Throwable) { + if (t is ControlFlowException) { + throw t + } - val attachment = runCatching { Attachment(file.name, file.readText()) }.getOrNull() - if (attachment != null) { - thisLogger().error("Failed to load template ${file.path}", t, attachment) - } else { - thisLogger().error("Failed to load template ${file.path}", t) - } - } - } + val attachment = runCatching { Attachment(file.name, file.readText()) }.getOrNull() + if (attachment != null) { + thisLogger().error("Failed to load template ${file.path}", t, attachment) + } else { + thisLogger().error("Failed to load template ${file.path}", t) + } + } + } - return true - } - } - VfsUtilCore.visitChildrenRecursively(repoRoot, visitor) return templates }