Skip to content

Debugger fails to attach when using "--enableAuth" with the "func host start" command #4740

@thern743

Description

@thern743

Problem:

When using vscode-azurefunctions extension, passing arguments to the func host start command in tasks.json will cause the debugger to fail to automatically attach to the process.

Details:

Modifying the command property for the func task type will cause the VS Code debugger to fail to attach to the process. After the function starts, the "func" tasks fails to properly detect the function host process having started and will give the following error:

"Error processing launch options at field: processId"

How to reproduce:

Given the following standard launch.json config:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to .NET Functions",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:azureFunctions.pickProcess}"
    }
  ]
}

and the following standard tasks.json config:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "clean (functions)",
      "command": "dotnet",
      "args": [
        "clean",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "type": "process",
      "problemMatcher": "$msCompile"
    },
    {
      "label": "build (functions)",
      "command": "dotnet",
      "args": [
        "build",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "type": "process",
      "dependsOn": "clean (functions)",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": "$msCompile"
    },
    {
      "label": "clean release (functions)",
      "command": "dotnet",
      "args": [
        "clean",
        "--configuration",
        "Release",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "type": "process",
      "problemMatcher": "$msCompile"
    },
    {
      "label": "publish (functions)",
      "command": "dotnet",
      "args": [
        "publish",
        "--configuration",
        "Release",
        "/property:GenerateFullPaths=true",
        "/consoleloggerparameters:NoSummary"
      ],
      "type": "process",
      "dependsOn": "clean release (functions)",
      "problemMatcher": "$msCompile"
    },
    {
      "type": "func",
      "dependsOn": "build (functions)",
      "options": {
        "cwd": "${workspaceFolder}/bin/Debug/net8.0"
      },
      "command": "host start",
      "isBackground": true,
      "problemMatcher": "$func-dotnet-watch"
    }
  ]
}

...modify "command": "host start" with the "--enableAuth" option:

E.g.:

{
      "type": "func",
      "dependsOn": "build (functions)",
      "options": {
        "cwd": "${workspaceFolder}/bin/Debug/net8.0"
      },
      "command": "host start --enableAuth",
      "isBackground": true,
      "problemMatcher": "$func-dotnet-watch"
    }

...should recreate the problem.

Workaround:

You will have to manually attach to the process. Modify the launch.json to execute a preLaunchTask and use the standard process picker. First, give the task a label:

tasks.json:

{
      "label": "func start",
      "type": "func",
      "dependsOn": "build (functions)",
      "options": {
        "cwd": "${workspaceFolder}/bin/Debug/net8.0"
      },
      "command": "host start --enableAuth",
      "isBackground": true,
      "problemMatcher": "$func-dotnet-watch"
    }

...add prelaunchTask:

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to .NET Functions",
      "type": "coreclr",
      "request": "attach",
      "preLaunchTask": "func start",
      "processId": "${command:pickProcess}"
    }
  ]
}

Root Cause:

The problem is due to the fact that the status check in funcHostTask.ts returns 401 Unauthorized. The telemetry output has the following error:

"Failed to detect running Functions host within '60' seconds"

** TELEMETRY("vscode-azurefunctions/azureFunctions.pickProcess", 1.19.3-alpha.0) properties={"isActivationEvent":"false","lastStep":"failedToConnectEmulator","result":"Failed","stack":"startFuncTask pickFuncProcess.ts:179:15\npickFuncProcess pickFuncProcess.ts:97:22","error":"Error","errorMessage":"Failed to detect running Functions host within \"60\" seconds. You may want to adjust the \"azureFunctions.pickProcessTimeout\" setting.","debugType":"coreclr","lastValidateStep":"emulatorRunning","projectLanguage":"C#","projectLanguageModel":"0","shouldContinue":"true","timeoutInSeconds":"60","x-ms-correlation-request-id":"80041f80-7d67-468f-a558-99979ee34c88","errorMessageV2":"Failed to detect running Functions host within \"60\" seconds. You may want to adjust the \"azureFunctions.pickProcessTimeout\" setting.","abexp.assignmentcontext":"vsliv368:30146709;copilot_t_ci:31333650;usemplatestapi:31297334;onetestforazureexpcf:31335614;6abeh943:31336334;3efgi100_wstrepl:31382709;trigger-command-fix:31379601;auto_model_enabled:31385282;copilot-gpt-5-mini:31400315;"}, measures={"duration":69.722,"tryGetProjectDuration":0.015,"tryGetProjectCount":2,"getNetProjFilesDuration":0.002,"getNetProjFilesCount":1}

This is due to the status check at the /admin/host/status GET endpoint when called by the following code:

const response = await sendRequestWithTimeout(context, statusRequest, statusRequestTimeout, undefined);

...when the host is listening only on HTTP and not HTTPS.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions