Skip to content

Commit

Permalink
Azure Functions: Isolated worker process ID not recognized when contr…
Browse files Browse the repository at this point in the history
…ol characters are present in process output #623 (#624)
  • Loading branch information
maartenba authored Aug 5, 2022
1 parent 8f796bb commit 34aa08e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<li>MSBuildEvaluator timeout breaks right-click + publish (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/611">#611</a>)</li>
<li>Dispose of response body when retrying is needed (<a href="https://github.com/JetBrains/azure-tools-for-intellij/pull/616">#616</a>)</li>
<li>SSLHandshakeException connecting to Azure Functions Core Tools release feed (<a href="https://youtrack.jetbrains.com/issue/RIDER-79897">RIDER-79897</a>)</li>
<li>Azure Functions: Isolated worker process ID not recognized when control characters are present in process output (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/623">#623</a>)</li>
</ul>
</html>
]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<li>MSBuildEvaluator timeout breaks right-click + publish (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/611">#611</a>)</li>
<li>Dispose of response body when retrying is needed (<a href="https://github.com/JetBrains/azure-tools-for-intellij/pull/616">#616</a>)</li>
<li>SSLHandshakeException connecting to Azure Functions Core Tools release feed (<a href="https://youtrack.jetbrains.com/issue/RIDER-79897">RIDER-79897</a>)</li>
<li>Azure Functions: Isolated worker process ID not recognized when control characters are present in process output (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/623">#623</a>)</li>
</ul>
<p>[3.50.0-2022.1]</p>
<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ run_config.run_function_app.form.function_app.before_run_tasks.build_function_pr
run_config.run_function_app.form.function_app.before_run_tasks.build_function_project_description=Build Functions project

run_config.run_function_app.debug.notification.title=Azure Functions - Debug
run_config.run_function_app.debug.notification.isolated_worker_process_terminated=Azure Functions host process terminated before the debugger could attach.
run_config.run_function_app.debug.notification.isolated_worker_pid_unspecified=Azure Functions host did not return isolated worker process id. Could not attach the debugger. Check the process output for more information.
run_config.run_function_app.debug.progress.starting_debugger=Waiting for Azure Functions host to start...
run_config.run_function_app.debug.ignore.externalconsole=The 'Use external console' option was ignored. Process Input/Output redirection is required to debug Azure Functions isolated workers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 JetBrains s.r.o.
* Copyright (c) 2021-2022 JetBrains s.r.o.
*
* All rights reserved.
*
Expand Down Expand Up @@ -51,7 +51,6 @@ import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.DotNetRuntime
import com.jetbrains.rider.runtime.apply
import com.microsoft.intellij.util.PluginUtil
import org.apache.commons.lang.StringUtils
import org.jetbrains.plugins.azure.RiderAzureBundle
import java.time.Duration

Expand All @@ -65,6 +64,7 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
private val logger = Logger.getInstance(AzureFunctionsDotNetCoreIsolatedDebugProfile::class.java)
private val waitDuration = Duration.ofMinutes(1)
private const val DOTNET_ISOLATED_DEBUG_ARGUMENT = "--dotnet-isolated-debug"
private val controlCharsRegex = "\u001B\\[[\\d;]*[^\\d;]".toRegex()
}

private var processId = 0
Expand All @@ -91,6 +91,15 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
pumpMessages(waitDuration) {
processId != 0 || targetProcessHandler.isProcessTerminated
}
if (targetProcessHandler.isProcessTerminated) {
logger.warn("Azure Functions host process terminated before the debugger could attach.")

// Notify user
PluginUtil.showErrorNotificationProject(
executionEnvironment.project,
RiderAzureBundle.message("run_config.run_function_app.debug.notification.title"),
RiderAzureBundle.message("run_config.run_function_app.debug.notification.isolated_worker_process_terminated"))
}
if (processId == 0) {
logger.warn("Azure Functions host did not return isolated worker process id.")

Expand Down Expand Up @@ -138,13 +147,13 @@ class AzureFunctionsDotNetCoreIsolatedDebugProfile(
}

override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
val line = event.text
val processText = event.text.replace(controlCharsRegex, "")

if (processId == 0 &&
StringUtils.containsIgnoreCase(line, "Azure Functions .NET Worker (PID: ") &&
StringUtils.containsIgnoreCase(line, ") initialized")) {
processText.contains("Azure Functions .NET Worker (PID: ", ignoreCase = true) &&
processText.contains(") initialized", ignoreCase = true)) {

val pidFromLog = line.substringAfter("PID: ")
val pidFromLog = processText.substringAfter("PID: ")
.dropWhile { !it.isDigit() }
.takeWhile { it.isDigit() }
.toInt()
Expand Down

0 comments on commit 34aa08e

Please sign in to comment.