Skip to content

Debug port sometimes ignored #3812

@danielniccoli

Description

@danielniccoli

I work with a multi-root workspace with one Azure Functions projects (mp_frontend) and one Azure Durable Functions project (mp_backend). I start both azure function hosts manually with the > Run Task palette command, instead of using F5. To run them concurrently, in project mp_backend I changed the ports of the http listener and debug server from the default 7071 to 7072, and the default 9091 to 9092 respectively. This mostly works.

However, from time to time the debug task of project mp_backend fails to start with error RuntimeError: Can't listen for client connections: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted. Whenever this happens, I triple-check that the ports 7072 and 9092 are not in use and I can confirm that they are not in use.

image

The error seems to be caused during the language worker startup and I assume that the Azure Functions extensions has troubles picking up the remote debug listen port (which is set to 9092 for project mp_backend) and so the language worker is trying to start on 9091, which is already used by the other project mp_frontend.

Task logs
*  Executing task in folder mp_backend: .venv\Scripts\python -m pip install -r requirements.txt 

Requirement already satisfied: azure-functions in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 5)) (1.15.0)
Requirement already satisfied: azure-functions-durable in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 6)) (1.2.4)
Requirement already satisfied: httpx in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 7)) (0.24.1)
Requirement already satisfied: pydantic[email] in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 8)) (2.1.1)
Requirement already satisfied: azure-identity in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 9)) (1.14.0)
Requirement already satisfied: msgraph-sdk in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from -r requirements.txt (line 10)) (1.0.0a14)
Requirement already satisfied: aiohttp>=3.6.2 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 6)) (3.8.5)
Requirement already satisfied: requests==2.* in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 6)) (2.31.0)
Requirement already satisfied: python-dateutil>=2.8.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 6)) (2.8.2)
Requirement already satisfied: furl>=2.1.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 6)) (2.1.3)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 6)) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 6)) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 6)) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 6)) (2023.7.22)
Requirement already satisfied: httpcore<0.18.0,>=0.15.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from httpx->-r requirements.txt (line 7)) (0.17.3)
Requirement already satisfied: sniffio in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages 
(from httpx->-r requirements.txt (line 7)) (1.3.0)
Requirement already satisfied: annotated-types>=0.4.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from pydantic[email]->-r requirements.txt (line 8)) (0.5.0)
Requirement already satisfied: pydantic-core==2.4.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from pydantic[email]->-r requirements.txt (line 8)) (2.4.0)
Requirement already satisfied: typing-extensions>=4.6.1 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from pydantic[email]->-r requirements.txt (line 8)) (4.7.1)
Requirement already satisfied: email-validator>=2.0.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from pydantic[email]->-r requirements.txt (line 8)) (2.0.0.post2)
Requirement already satisfied: azure-core<2.0.0,>=1.11.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-identity->-r requirements.txt (line 9)) (1.29.2)
Requirement already satisfied: cryptography>=2.5 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-identity->-r requirements.txt (line 9)) (41.0.3)
Requirement already satisfied: msal<2.0.0,>=1.20.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-identity->-r requirements.txt (line 9)) (1.23.0)
Requirement already satisfied: msal-extensions<2.0.0,>=0.3.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-identity->-r requirements.txt (line 9)) (1.0.0)
Requirement already satisfied: microsoft-kiota-abstractions<0.8,>=0.7 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (0.7.1)
Requirement already satisfied: microsoft-kiota-authentication-azure>=0.2 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (0.2.0)
Requirement already satisfied: microsoft-kiota-serialization-json<0.5,>=0.4 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (0.4.0)
Requirement already satisfied: microsoft-kiota-serialization-text>=0.2.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (0.2.1)
Requirement already satisfied: microsoft-kiota-http<0.6,>=0.5 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (0.5.0)
Requirement already satisfied: msgraph-core>=1.0.0a2 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msgraph-sdk->-r requirements.txt (line 10)) (1.0.0a4)
Requirement already satisfied: attrs>=17.3.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (23.1.0)
Requirement already satisfied: multidict<7.0,>=4.5 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (6.0.4)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (4.0.2)
Requirement already satisfied: yarl<2.0,>=1.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (1.9.2)
Requirement already satisfied: frozenlist>=1.1.1 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (1.4.0)
Requirement already satisfied: aiosignal>=1.1.2 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 6)) (1.3.1)
Requirement already satisfied: six>=1.11.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from azure-core<2.0.0,>=1.11.0->azure-identity->-r requirements.txt (line 9)) (1.16.0)
Requirement already satisfied: cffi>=1.12 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from cryptography>=2.5->azure-identity->-r requirements.txt (line 9)) (1.15.1)
Requirement already satisfied: dnspython>=2.0.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from email-validator>=2.0.0->pydantic[email]->-r requirements.txt (line 8)) (2.4.1)
Requirement already satisfied: orderedmultidict>=1.0.1 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from furl>=2.1.0->azure-functions-durable->-r requirements.txt (line 6)) (1.0.1)
Requirement already satisfied: h11<0.15,>=0.13 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from httpcore<0.18.0,>=0.15.0->httpx->-r requirements.txt (line 7)) (0.14.0)
Requirement already satisfied: anyio<5.0,>=3.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from httpcore<0.18.0,>=0.15.0->httpx->-r requirements.txt (line 7)) (3.7.1)
Requirement already satisfied: uritemplate>=4.1.1 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from microsoft-kiota-abstractions<0.8,>=0.7->msgraph-sdk->-r requirements.txt (line 10)) (4.1.1)
Requirement already satisfied: PyJWT[crypto]<3,>=1.0.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msal<2.0.0,>=1.20.0->azure-identity->-r requirements.txt (line 9)) (2.8.0)
Requirement already satisfied: portalocker<3,>=1.6 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from msal-extensions<2.0.0,>=0.3.0->azure-identity->-r requirements.txt (line 9)) (2.7.0)
Requirement already satisfied: exceptiongroup in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from anyio<5.0,>=3.0->httpcore<0.18.0,>=0.15.0->httpx->-r requirements.txt (line 7)) (1.1.2)
Requirement already satisfied: pycparser in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from cffi>=1.12->cryptography>=2.5->azure-identity->-r requirements.txt (line 9)) (2.21)
Requirement already satisfied: h2<5,>=3 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from httpx->-r requirements.txt (line 7)) (4.1.0)
Requirement already satisfied: pywin32>=226 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from portalocker<3,>=1.6->msal-extensions<2.0.0,>=0.3.0->azure-identity->-r requirements.txt (line 9)) (306)
Requirement already satisfied: hyperframe<7,>=6.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from h2<5,>=3->httpx->-r requirements.txt (line 7)) (6.0.1)
Requirement already satisfied: hpack<5,>=4.0 in c:\users\niccodan\source\repos\multipass\mp_backend\.venv\lib\site-packages (from h2<5,>=3->httpx->-r requirements.txt (line 7)) (4.0.0)
*  Terminal will be reused by tasks, press any key to close it. 

*  Executing task in folder mp_backend: .venv\Scripts\activate ; func host start 

Found Python version 3.10.11 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5198 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.21.1.20667

[2023-08-21T09:15:49.836Z] Language Worker Process exited. Pid=15036.
[2023-08-21T09:15:49.839Z] py exited with code 1 (0x1).     log.reraise_exception("{0}() failed:", func.__name__, level="info"),    raise RuntimeError(str(endpoints["error"])),RuntimeError: Can't listen for client connections: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted.
[2023-08-21T09:16:49.148Z] Starting worker process failed
[2023-08-21T09:16:49.150Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
[2023-08-21T09:16:49.152Z] Failed to start language worker process for runtime: (null). workerId:61ccc680-7f3b-4af3-a289-89661b7cfac6
[2023-08-21T09:16:49.155Z] Removing errored webhost language worker channel for runtime: python workerId:61ccc680-7f3b-4af3-a289-89661b7cfac6  
[2023-08-21T09:16:49.156Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
[2023-08-21T09:16:50.131Z] Traceback (most recent call last):
[2023-08-21T09:16:50.134Z]   File "C:\Users\niccodan\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main   
[2023-08-21T09:16:50.136Z]     return _run_code(code, main_globals, None,
[2023-08-21T09:16:50.137Z]   File "C:\Users\niccodan\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
[2023-08-21T09:16:50.138Z]     exec(code, run_globals)
[2023-08-21T09:16:50.139Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
[2023-08-21T09:16:50.140Z]     cli.main()
[2023-08-21T09:16:50.141Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
[2023-08-21T09:16:50.142Z]     run()
[2023-08-21T09:16:50.142Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 268, in run_file
[2023-08-21T09:16:50.144Z]     start_debugging(target)
[2023-08-21T09:16:50.145Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 256, in start_debugging
[2023-08-21T09:16:50.146Z]     debugpy.listen(options.address)
[2023-08-21T09:16:50.147Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\public_api.py", line 31, in wrapper
[2023-08-21T09:16:50.149Z]     return wrapped(*args, **kwargs)
[2023-08-21T09:16:50.150Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 143, in debug
[2023-08-21T09:16:50.152Z]     log.reraise_exception("{0}() failed:", func.__name__, level="info")
[2023-08-21T09:16:50.153Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 141, in debug
[2023-08-21T09:16:50.154Z]     return func(address, settrace_kwargs, **kwargs)
[2023-08-21T09:16:50.156Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 262, in listen
[2023-08-21T09:16:50.157Z]     raise RuntimeError(str(endpoints["error"]))
[2023-08-21T09:16:50.159Z] RuntimeError: Can't listen for client connections: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
[2023-08-21T09:16:51.092Z] Traceback (most recent call last):
[2023-08-21T09:16:51.094Z]   File "C:\Users\niccodan\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main   
[2023-08-21T09:16:51.096Z]     return _run_code(code, main_globals, None,
[2023-08-21T09:16:51.097Z]   File "C:\Users\niccodan\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
[2023-08-21T09:16:51.098Z]     exec(code, run_globals)
[2023-08-21T09:16:51.099Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
[2023-08-21T09:16:51.100Z]     cli.main()
[2023-08-21T09:16:51.101Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
[2023-08-21T09:16:51.103Z]     run()
[2023-08-21T09:16:51.104Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 268, in run_file
[2023-08-21T09:16:51.105Z]     start_debugging(target)
[2023-08-21T09:16:51.106Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 256, in start_debugging
[2023-08-21T09:16:51.108Z]     debugpy.listen(options.address)
[2023-08-21T09:16:51.109Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\public_api.py", line 31, in wrapper
[2023-08-21T09:16:51.110Z]     return wrapped(*args, **kwargs)
[2023-08-21T09:16:51.111Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 143, in debug
[2023-08-21T09:16:51.112Z]     log.reraise_exception("{0}() failed:", func.__name__, level="info")
[2023-08-21T09:16:51.113Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 141, in debug
[2023-08-21T09:16:51.115Z]     return func(address, settrace_kwargs, **kwargs)
[2023-08-21T09:16:51.116Z]   File "c:\Users\niccodan\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy/..\debugpy\server\api.py", line 262, in listen
[2023-08-21T09:16:51.117Z]     raise RuntimeError(str(endpoints["error"]))
[2023-08-21T09:16:51.119Z] RuntimeError: Can't listen for client connections: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
[2023-08-21T09:16:51.130Z] Language Worker Process exited. Pid=25812.
[2023-08-21T09:16:51.132Z] py exited with code 1 (0x1).     log.reraise_exception("{0}() failed:", func.__name__, level="info"),    raise RuntimeError(str(endpoints["error"])),RuntimeError: Can't listen for client connections: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted.
[2023-08-21T09:16:51.141Z] Exceeded language worker restart retry count for runtime:python. Shutting down and proactively recycling the Functions Host to recover
[2023-08-21T09:17:50.200Z] Starting worker process failed
[2023-08-21T09:17:50.203Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
[2023-08-21T09:17:50.204Z] Failed to start language worker process for runtime: (null). workerId:71e7699e-68b7-4e1f-99c3-365ba2dc801f
[2023-08-21T09:17:50.592Z] A host error has occurred during startup operation '968eb9f7-e015-42d4-aabd-f857725546c1'.
[2023-08-21T09:17:50.594Z] Microsoft.Azure.WebJobs.Script: Object reference not set to an instance of an object.
[2023-08-21T09:17:50.602Z] Failed to stop host instance 'ca441de7-d7af-4cee-9f94-a930b7fed513'.
[2023-08-21T09:17:50.604Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2023-08-21T09:17:50.613Z] Host startup operation has been canceled

The tasks.json in both projects are identical and left unchanged.

PROJECT_ROOT\.vscode\tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "func",
      "label": "func: host start",
      "command": "host start",
      "problemMatcher": "$func-python-watch",
      "isBackground": true,
      "dependsOn": "pip install (functions)"
    },
    {
      "label": "pip install (functions)",
      "type": "shell",
      "osx": {
        "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
      },
      "windows": {
        "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
      },
      "linux": {
        "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
      },
      "problemMatcher": []
    }
  ]
}

The launch.json in both projects are identical and left unchanged, except for mp_backend\.vscode\launch.json where I changed port from 9091 to 9092.

mp_backend\.vscode\tasks.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Python Functions",
      "type": "python",
      "request": "attach",
      "port": 9092,
      "preLaunchTask": "func: host start"
    }
  ]
}

The local.settings.json in both projects are identical, except for mp_backend\local.settings.json where I changed the LocalHttpPort from 7071 to 7072.

mp_backend\local.settings.json
{
  "IsEncrypted": false,
  "Values": {
  "FUNCTIONS_WORKER_RUNTIME": "python",
  "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
  "AZURE_TENANT_ID": "3817f61a-40c0-428b-8591-37b24bf6ceeb",
  "AZURE_CLIENT_ID": "da27fd11-a79b-4eb1-9d03-d92ccaa82fcb",
  "AZURE_CLIENT_SECRET": "UO98Q~iogInhqExbligFj8uEhu6k8bicHbqoBcz0"
  
  },
  "Host": {
  "LocalHttpPort": 7072
  }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions