-
Notifications
You must be signed in to change notification settings - Fork 124
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
Comments
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:\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)
[swa] |
Hi @scafaria , can you please try starting SWACLI using the command |
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: And then I ran: And to my surprise it says And of course swa start http://localhost:5000/ doesn't work for me either right now. Sorry I can't be more helpful. |
Please feel free to track the original issue #663 |
@scafaria Thank you very much for your feedback. If you still care about this issue, please try the following steps:
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. |
Close the issue. Please feel free to open it if the error occurs. |
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
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:
No workflow config folder found at c:\PositiveSum\Code\Samples\Test4.github\workflows
Validating user workflow config (BEFORE):
Validating user workflow config (AFTER):
User workflow config:
Starting the SWA emulator with the following configuration:
[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
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:
No workflow config folder found at c:\PositiveSum\Code\Samples\Test4.github\workflows
Validating user workflow config (BEFORE):
Validating user workflow config (AFTER):
User workflow config:
Starting the SWA emulator with the following configuration:
[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
The text was updated successfully, but these errors were encountered: