Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Api crashes CLI; Port 7071 already in use #609

Closed
scafaria opened this issue Nov 22, 2022 · 6 comments
Closed

Using Api crashes CLI; Port 7071 already in use #609

scafaria opened this issue Nov 22, 2022 · 6 comments
Labels

Comments

@scafaria
Copy link

ISSUE:

Error Port 7071 is already in use. Switching to 7072 doesn't help either. Using the Api crashes CLI.

USING:

Node v16.18.1, swa v1.0.3, Windows 11, Visual Studio 2022, Blazor, Core Tools v4.0.4895, Function Runtime Version: 4.13.0.19486

SETUP

Add new Blazor Client and Api projects to solution. Set both as startup projects.

Api launchSettings.json of:

{
"profiles": {
"Api": {
"commandName": "Project",
"commandLineArgs": "--cors * --port 7071",
"launchBrowser": false
}
}
}

Client launchSettings.json of

{
"iisSettings": { accepted defaults },
"profiles": {
"Client": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": { accepted defaults}
}
}
}

FIRST

swa start https://localhost:5000 --api-location Api --verbose=silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at c:\PositiveSum\Code\Samples\Test4\swa-cli.config.json


  • WARNING: This emulator may not match the cloud environment exactly. *
  • Always deploy and test your app in Azure. *

Checking if localhost:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
appDevserverUrl provided, we will try connect to dev server at .
Trying to read workflow config with values:

  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • outputLocation: https://localhost:5000
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
    No workflow config folder found at c:\PositiveSum\Code\Samples\Test4.github\workflows
    Validating user workflow config (BEFORE):
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • outputLocation: https://localhost:5000
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
    Validating user workflow config (AFTER):
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
  • outputLocation: https://localhost:5000
    User workflow config:
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
  • outputLocation: https://localhost:5000
    Starting the SWA emulator with the following configuration:
  • ssl:
    • 0: false
    • 1:
    • 2:
  • env:
    • SWA_RUNTIME_CONFIG_LOCATION: c:\PositiveSum\Code\Samples\Test4
    • SWA_RUNTIME_WORKFLOW_LOCATION:
    • SWA_CLI_DEBUG: silly
    • SWA_CLI_API_PORT: 7071
    • SWA_CLI_APP_LOCATION: c:\PositiveSum\Code\Samples\Test4
    • SWA_CLI_OUTPUT_LOCATION: https://localhost:5000
    • SWA_CLI_API_LOCATION: c:\PositiveSum\Code\Samples\Test4\Api
    • SWA_CLI_HOST: localhost
    • SWA_CLI_PORT: 4280
    • SWA_CLI_APP_SSL: false
    • SWA_CLI_APP_SSL_CERT:
    • SWA_CLI_APP_SSL_KEY:
    • SWA_CLI_STARTUP_COMMAND:
    • SWA_CLI_VERSION: 1.0.3
    • SWA_CLI_SERVER_TIMEOUT: 60
    • SWA_CLI_OPEN_BROWSER: false
  • commands:
    • swa: node "C:\Users\Vince Scafaria\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js"
    • api: cd "c:\PositiveSum\Code\Samples\Test4\Api" && func start --cors "*" --port 7071
    • run:
      [api] MSBuild version 17.4.0+18d5aef85 for .NET
      [api] Determining projects to restore...
      [swa] No staticwebapp.config.json found in current project
      [swa] Validating dev server config:
      [swa] - url: https://localhost:5000
      [swa] - timeout: 60
      [swa] Checking if localhost:5000 is accepting TCP connections...
      [swa] - Waiting for https://localhost:5000 to be ready
      [api] All projects are up-to-date for restore.
      [api] Api -> c:\PositiveSum\Code\Samples\Test4\Api\bin\output\Api.dll
      [api]
      [api] Build succeeded.
      [api] 0 Warning(s)
      [api] 0 Error(s)
      [api]
      [api] Time Elapsed 00:00:08.44
      [api]
      [api]
      [api]
      [api] Azure Functions Core Tools
      [api] Core Tools Version: 4.0.4895 Commit hash: N/A (64-bit)
      [api] Function Runtime Version: 4.13.0.19486
      [api]
      [api] [2022-11-22T13:08:01.729Z] Found c:\PositiveSum\Code\Samples\Test4\Api\Api.csproj. Using for user secrets file configuration.
      [api]
      [api] Functions:
      [api]
      [api] Function1: [GET,POST] http://localhost:7071/api/Function1
      [api]
      [api] For detailed output, run func with --verbose flag.

SECOND hit F5.

NOW

I see in the swa start console window:

[swa] Validating dev server config:
[swa] - url: http://localhost:7071
[swa] - timeout: 60
[swa] Checking if localhost:7071 is accepting TCP connections...
[swa]
[swa] Using dev server for static content:
[swa] https://localhost:5000
[swa]
[swa] Serving API:
[swa] c:\PositiveSum\Code\Samples\Test4\Api
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.

AND

I see the Client swa launches successfully at https://localhost:5000/.

BUT

in the func.exe window I see:

Port 7071 is unavailable. Close the process using that port, or specify another port using --port [-p].

WHILE

in the dotnet.exe window I see:

info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\PositiveSum\Code\Samples\Test4\Client
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0] sending error response for id: msg-A03F9919BF36377F6CFD7ED4445ED09F:::1017 -> [Result: IsOk: False, IsErr: True, Value: , Error: { "code": -32601, "message": "'DotnetDebugger.setDebuggerProperty' wasn't found" } ]
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0] sending error response for id: msg-A03F9919BF36377F6CFD7ED4445ED09F:::1018 -> [Result: IsOk: False, IsErr: True, Value: , Error: { "code": -32601, "message": "'DotnetDebugger.setDebuggerProperty' wasn't found" } ]

NEXT

Despite seeing the error about port 7071 in use, I forge ahead and try hitting the Api endpoint using port 4280.

http://localhost:7071/api/Function1

This works ONCE and then crashes CLI.

The console reads:

Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]
[swa]
[swa] --------------------------------------------------------
[swa] ------------------- processing route -------------------
[swa] --------------------------------------------------------
[swa] processing /api/Function1
[swa] checking for matching route
[swa] checking auth request
[swa] - not an auth request
[swa] checking function request
[swa] checking HTTP method: GET
[swa] - function or auth request detected, method is valid
[swa] checking for query params
[swa] checking rewrite auth login request
[swa] checking rewrite auth logout request
[swa] checking authorizations for route
[swa] - no matching rule
[swa] - access authorized
[swa] using userConfig
[swa] - userConfig:
[swa] function request detected. Proxying to Azure Functions emulator
[swa] - target: http://localhost:7071
[swa] GET http://localhost:7071/api/Function1 (proxy)
[swa] injecting headers to Functions request:
[swa] - x-ms-request-id: SWA-CLI-TOMADOU33AR
[swa] injecting client principal to Functions request:
[swa] - no valid cookie found
[api] [2022-11-22T13:28:15.011Z] Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=81e6014d-6061-43d4-8349-59ac5e08abce)
[api] [2022-11-22T13:28:15.036Z] C# HTTP trigger function processed a request.
[api] [2022-11-22T13:28:15.146Z] Executed 'Function1' (Succeeded, Id=81e6014d-6061-43d4-8349-59ac5e08abce, Duration=148ms)
[swa] getting response from remote host
[swa] GET http://localhost:4280/api/Function1 - 200
[swa]
[swa] --------------------------------------------------------
[swa] ------------------- processing route -------------------
[swa] --------------------------------------------------------
[swa] processing /favicon.ico
[swa] checking for matching route
[swa] checking auth request
[swa] - not an auth request
[swa] checking function request
[swa] - not a function request
[swa] checking HTTP method: GET
[swa] - method is valid (allow-list: GET,HEAD,OPTIONS)
[swa] checking for query params
[swa] checking rewrite auth login request
[swa] checking rewrite auth logout request
[swa] checking authorizations for route
[swa] - no matching rule
[swa] - access authorized
[swa] using userConfig
[swa] - userConfig:
[swa] checking storage content
[swa] remote dev server detected.
[swa] - url: /favicon.ico
[swa] - target: https://localhost:5000
[swa] customUrl: false
[swa] is4xx: false
[swa] remote dev server detected. Proxying request
[swa] - url: /favicon.ico
[swa] - code: 200
[swa] GET https://localhost:5000/favicon.ico (proxy)
[swa] killing SWA CLI
[swa] node "C:\Users\Vince Scafaria\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
--> Sending SIGTERM to other processes..
[api] cd "c:\PositiveSum\Code\Samples\Test4\Api" && func start --cors "*" --port 7071 exited with code 1
✖ SWA emulator stoped because API server exited with code 1.

Changing the port to 7072 is ignored

I changed the fn settings to:

{
"profiles": {
"Api": {
"commandName": "Project",
"commandLineArgs": "--cors * --port 7072",
"launchBrowser": false
}
}
}

And modified the command executed, yet per the output, the directive to move to 7072 seems to be ignored:

c:\PositiveSum\Code\Samples\Test4>swa start https://localhost:5000 --api-location Api --port 7072 --verbose=silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at c:\PositiveSum\Code\Samples\Test4\swa-cli.config.json


  • WARNING: This emulator may not match the cloud environment exactly. *
  • Always deploy and test your app in Azure. *

Checking if localhost:7072 is accepting TCP connections...
Port 7072 is available. Use it.
Resolved port number: 7072
appDevserverUrl provided, we will try connect to dev server at .
Trying to read workflow config with values:

  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • outputLocation: https://localhost:5000
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
    No workflow config folder found at c:\PositiveSum\Code\Samples\Test4.github\workflows
    Validating user workflow config (BEFORE):
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • outputLocation: https://localhost:5000
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
    Validating user workflow config (AFTER):
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
  • outputLocation: https://localhost:5000
    User workflow config:
  • appLocation: c:\PositiveSum\Code\Samples\Test4
  • apiLocation: c:\PositiveSum\Code\Samples\Test4\Api
  • outputLocation: https://localhost:5000
    Starting the SWA emulator with the following configuration:
  • ssl:
    • 0: false
    • 1:
    • 2:
  • env:
    • SWA_RUNTIME_CONFIG_LOCATION: c:\PositiveSum\Code\Samples\Test4
    • SWA_RUNTIME_WORKFLOW_LOCATION:
    • SWA_CLI_DEBUG: silly
    • SWA_CLI_API_PORT: 7071
    • SWA_CLI_APP_LOCATION: c:\PositiveSum\Code\Samples\Test4
    • SWA_CLI_OUTPUT_LOCATION: https://localhost:5000
    • SWA_CLI_API_LOCATION: c:\PositiveSum\Code\Samples\Test4\Api
    • SWA_CLI_HOST: localhost
    • SWA_CLI_PORT: 7072
    • SWA_CLI_APP_SSL: false
    • SWA_CLI_APP_SSL_CERT:
    • SWA_CLI_APP_SSL_KEY:
    • SWA_CLI_STARTUP_COMMAND:
    • SWA_CLI_VERSION: 1.0.3
    • SWA_CLI_SERVER_TIMEOUT: 60
    • SWA_CLI_OPEN_BROWSER: false
  • commands:
    • swa: node "C:\Users\Vince Scafaria\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js"
    • api: cd "c:\PositiveSum\Code\Samples\Test4\Api" && func start --cors "*" --port 7071
    • run:
      [api] MSBuild version 17.4.0+18d5aef85 for .NET
      [api] Determining projects to restore...
      [swa] No staticwebapp.config.json found in current project
      [swa] Validating dev server config:
      [swa] - url: https://localhost:5000
      [swa] - timeout: 60
      [swa] Checking if localhost:5000 is accepting TCP connections...
      [swa] - Waiting for https://localhost:5000 to be ready
      [api] All projects are up-to-date for restore.
      [api] Api -> c:\PositiveSum\Code\Samples\Test4\Api\bin\output\Api.dll
      [api]
      [api] Build succeeded.
      [api] 0 Warning(s)
      [api] 0 Error(s)
      [api]
      [api] Time Elapsed 00:00:02.98
      [api]
      [api]
      [api]
      [api] Azure Functions Core Tools
      [api] Core Tools Version: 4.0.4895 Commit hash: N/A (64-bit)
      [api] Function Runtime Version: 4.13.0.19486
      [api]
      [api] [2022-11-22T13:33:41.512Z] Found c:\PositiveSum\Code\Samples\Test4\Api\Api.csproj. Using for user secrets file configuration.
      [api]
      [api] Functions:
      [api]
      [api] Function1: [GET,POST] http://localhost:7071/api/Function1
      [api]
      [api] For detailed output, run func with --verbose flag.
      [swa] killing SWA CLI
      [swa] node "C:\Users\Vince Scafaria\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
      --> Sending SIGTERM to other processes..
      [api] cd "c:\PositiveSum\Code\Samples\Test4\Api" && func start --cors "*" --port 7071 exited with code 0
@scafaria
Copy link
Author

ANOTHER related scenario / repro case

(providing a code repository...)

Following along with Code 5-12 from the book Beginning Azure Static Web Apps and using the repository for chapter 5 here...

Navigating to http://localhost:4280/ causes the CLI to crash/stop.

Microsoft Windows [Version 10.0.22621.819]
(c) Microsoft Corporation. All rights reserved.

C:\Users\User Name>cd C:\MyRepos\Code\Samples\beginning-azure-static-web-apps\chapter-5

C:\MyRepos\Code\Samples\beginning-azure-static-web-apps\chapter-5>swa start https://localhost:5000

Welcome to Azure Static Web Apps CLI (1.0.3)


  • WARNING: This emulator may not match the cloud environment exactly. *
  • Always deploy and test your app in Azure. *

[swa]
[swa] Using workflow file:
[swa] C:\MyRepos\Code\Samples\beginning-azure-static-web-apps\chapter-5.github\workflows\azure-static-web-apps-agreeable-wave-01cef0403.yml
[swa]
[swa] Using dev server for static content:
[swa] https://localhost:5000
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]
[swa] GET https://localhost:5000/ (proxy)
[swa] node "C:\Users\User Name\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0

@rupareddy5-21
Copy link
Contributor

Hi @scafaria , can you please try starting SWACLI using the command swa start http://localhost:5000/ and let us know if the issue still persists. Thanks

@scafaria
Copy link
Author

scafaria commented Feb 6, 2023

I've moved to other workflows these last few weeks, but I want to help you diagnose so I'm trying to remember how to get back into this... I ran from a command line:

npm install -g @azure/static-web-apps-cli

And it said:
changed 342 packages, and audited 343 packages in 38s
so I figured it worked.

And then I ran:
swa --version

And to my surprise it says
"'swa' is not recognized as an internal or external command"

And of course swa start http://localhost:5000/ doesn't work for me either right now. Sorry I can't be more helpful.

@rupareddy5-21
Copy link
Contributor

Please feel free to track the original issue #663

@cjk7989
Copy link
Contributor

cjk7989 commented Aug 18, 2023

@scafaria Thank you very much for your feedback. If you still care about this issue, please try the following steps:

  1. Install the latest version of swa-cli.
  2. cd into your Blazor app folder and manually start your Blazor app with api, keeping commandLineArgs as 7071. (After that port 5000 and 7071 should be reachable)
  3. Run this command: swa start https://localhost:5000/ --api-devserver-url https://localhost:7071/ --verbose=silly

The reason is that you are using a dev server (Blazor) with api, so just set api-devserver-url instead of api-location (which will use azure-function-core-tools to start api again, leading to "port 7071 already in use").

Hope that can help.

@cjk7989
Copy link
Contributor

cjk7989 commented Oct 31, 2023

Close the issue. Please feel free to open it if the error occurs.

@cjk7989 cjk7989 closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants