azure-functions-host: [LanguageWorker][Debugging]Function Host fails to restart language worker process on file edit if debugger is attached

I’m launching the debugger from VSCode. The run time is v2, and language is Node.js.

Every time I make a change to the file, the debug process crashes and I have to start the function again, as well as the debug session.

  • Function App version (1.0 or 2.0): 2.0
  • Function App name: runnning locally

I’m on Windows!

Repro steps

  1. Download VSCode
  2. Install Node.js
  3. Install the Azure Functions Runtime
  4. Create a function
  5. Launch a debug session
  6. Make a change to function, save file, see crash.

Expected behavior

I don’t expect the function runtime to crash.

Here’s a sample log from when it happens:

info: Host.General[0]
     Restarting host.
info: Host.General[0]
     Building host: startup suppressed:False, configuration suppressed: False
info: Host.Startup[0]
     Reading host configuration file 'C:\volunteerManagement\host.json'
info: Host.Startup[0]
     Host configuration file read:
     {
       "version": "2.0"
     }
[10/1/2018 7:00:19 PM] Initializing Host.
[10/1/2018 7:00:19 PM] Host initialization: ConsecutiveErrors=0, StartupCount=2
[10/1/2018 7:00:19 PM] Starting JobHost
[10/1/2018 7:00:19 PM] Starting Host (HostId=desktoplglnm4m-1873661633, InstanceId=aada58ee-e906-47b5-bde3-669548211425, Version=2.0.12115.0, ProcessId=4536, AppDomainId=1, Debug=False, FunctionsExtensionVersion=)
[10/1/2018 7:00:19 PM] Starting language worker process:node  --inspect=5858 "C:\Users\Admin\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\node\dist/src/nodejsWorker.js" --host 127.0.0.1 --port 49634 --workerId 40137e5e-1db2-4007-9067-57bcd26ecfb2 --requestId 2fdb954b-ba34-4ac7-862c-d785b047d56b --grpcMaxMessageLength 134217728
[10/1/2018 7:00:19 PM] node process with Id=7328 started
[10/1/2018 7:00:19 PM] Generating 4 job function(s)
[10/1/2018 7:00:19 PM] Found the following functions:
[10/1/2018 7:00:19 PM] Host.Functions.getEventsForRegistration
[10/1/2018 7:00:19 PM] Host.Functions.getIfCurrent
[10/1/2018 7:00:19 PM] Host.Functions.registerMember[10/1/2018 7:00:19 PM] Starting inspector on 127.0.0.1:5858 failed: address already in use

[10/1/2018 7:00:19 PM] Host.Functions.signupEvent
[10/1/2018 7:00:19 PM]
[10/1/2018 7:00:19 PM] Language Worker Process exited.
[10/1/2018 7:00:19 PM] Host initialized (278ms)
[10/1/2018 7:00:19 PM] node exited with code 12
.
[10/1/2018 7:00:19 PM] Host started (288ms)
[10/1/2018 7:00:19 PM] Job host started
[10/1/2018 7:00:19 PM] Starting language worker process:node  --inspect=5858 "C:\Users\Admin\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\node\dist/src/nodejsWorker.js" --host 127.0.0.1 --port 49634 --workerId cc3e30e5-2c72-40f7-baa3-e685c0c2adfc --requestId ad1b93ad-e6aa-4021-a66c-1bd7cd8498e3 --grpcMaxMessageLength 134217728
[10/1/2018 7:00:19 PM] node process with Id=22756 started
[10/1/2018 7:00:19 PM] Stopping JobHost
[10/1/2018 7:00:19 PM] Job host stopped
info: Host.General[0]
     Host restarted.
[10/1/2018 7:00:19 PM] Language Worker Process exited.[10/1/2018 7:00:19 PM] Debugger listening on ws://127.0.0.1:5858/ac861383-518f-451b-affe-65d33b3c5d73

[10/1/2018 7:00:20 PM] node exited with code -1
.
[10/1/2018 7:00:20 PM] For help, see: https://nodejs.org/en/docs/inspector
[10/1/2018 7:00:20 PM] Worker cc3e30e5-2c72-40f7-baa3-e685c0c2adfc connecting on 127.0.0.1:49634
[10/1/2018 7:00:24 PM] Host lock lease acquired by instance ID '0000000000000000000000004C66A269'.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 25 (9 by maintainers)

Most upvoted comments

Any update on when this’ll be fixed? Makes it hard to follow a real flow of work

I’m also seeing this issue.

Work for this is currently in progress, but we expect completion to happen next sprint. Updated the target to reflect that.

This issue is resolved on the azure-functions-host side with host versions > 3.0.15149 (currently, this means our next release).

However, this will not automatically enable a continuous debugging experience on file change. Changes also need to be made to the VS Code Extension, and those can be tracked here: https://github.com/microsoft/vscode-azurefunctions/issues/781

In addition to a resolution for https://github.com/microsoft/vscode-azurefunctions/issues/781, for Python functions, this change needs to be made: https://github.com/microsoft/vscode-azurefunctions/pull/2576

Closing as issue described in title, “Function Host fails to restart language worker process on file edit if debugger is attached,” is resolved.

this is a surprisingly bad developer experience, which is weird, because the vs extensions seems polished otherwise.

But having to kill the process all the time is just annoying.

Didn’t get much time to work on this larger item with being on-call, pushing to next sprint. Apologies all, still definitely a priority 😃

After a discussion with @fabiocav @anthonychu @pragnagopa and @mhoeger, we believe that the issue occurs when there is an overlap while recycling processes, that results in the new process fails to open the debugging port as it is still being held by the process that is being brought down.

The current approach that we are thinking is to remove the overlapping condition when running the host in development environments.

@Wankishh - what’s the scenario you are creating js files for? From our perspective this is an issue that affects people debugging their local code and not a production issue. Remember that function invocations should be regarded as stateless. If you are trying to preserve state between function invocations, you should explore Durable Functions.

For anybody who may have an interest in how to get a decent workflow up and running in VSCode until this issue is resolved I’ve put the following together to allow me to automatically start/stop the functions host when I launch the debugger.

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Run Functions host and attach",
            "protocol": "inspector",
            "preLaunchTask": "Compile TS, Run Functions (Shell)",
            "postDebugTask": "Stop Functions",
            "outFiles": [ "{workspaceRoot}/TypeScriptFunction/index.js" ],
            "port": 5858
        },
        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "protocol": "inspector",
            "outFiles": [ "{workspaceRoot}/TypeScriptFunction/index.js" ],
            "port": 5858
        }
    ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run Functions",
      "type": "shell",
      "command": "sh scripts/functions_host_background.sh",
      "problemMatcher": []
    },
    {
      "label": "Stop Functions",
      "type": "shell",
      "command": "tmux kill-session -t azure-functions-playground",
      "problemMatcher": []
    },
    {
      "label": "Compile TypeScript",
      "type": "shell",
      "command": "tsc --outDir TypeScriptFunction --sourceMap --lib es2015 TypeScriptFunction/index.ts",
      "problemMatcher": []
    },
    {
      "label": "Compile TS, Run Functions (Compound)",
      "type": "shell",
      "dependsOn": [
        "Compile TypeScript",
        "Run Functions"
      ],
      "problemMatcher": []
    },
    {
      "label": "Compile TS, Run Functions (Shell)",
      "type": "shell",
      "command": "tsc --outDir TypeScriptFunction --sourceMap --lib es2015 TypeScriptFunction/index.ts;sh scripts/functions_host_background.sh",
      "problemMatcher": []
    }
  ]
}

functions_host_background.sh

tmux kill-session -t azure-functions-playground
tmux start-server
tmux new-session -d -s azure-functions-playground -n host
tmux send-keys -t azure-functions-playground:host "func host start --language-worker -- \"--inspect=5858\"" C-m

You need tmux, but it makes life bearable…

Add the presentation options to your tasks to keep them out of sight.

I couldn’t use the compound key because of this bug: https://github.com/Microsoft/vscode/issues/52737