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

Running with the debugger does not respect LocalHttpPort in local.settings.json #584

Closed
leftler opened this issue Nov 10, 2017 · 19 comments
Closed

Comments

@leftler
Copy link

leftler commented Nov 10, 2017

  1. Create a new function app
  2. Update the NuGet package Microsoft.NET.Sdk.Functions to 1.0.6
  3. Edit local.settings.json to be the following
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": ""
  },
  "Host": {
    "LocalHttpPort": 7072,
    "CORS": "*"
  }
}
  1. Add a simple HttpTrigger using the default template
  2. Run function app.

In the console window you will see

[11/10/2017 4:32:33 PM] Reading host configuration file 'D:\Temp\ExampleApp\ExampleApp\bin\Debug\net461\host.json'
[11/10/2017 4:32:34 PM] Host configuration file read:
[11/10/2017 4:32:34 PM] {
}
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[11/10/2017 4:32:34 PM] Loaded custom extension 'BotFrameworkConfiguration'
[11/10/2017 4:32:34 PM] Loaded custom extension 'SendGridConfiguration'
[11/10/2017 4:32:34 PM] Loaded custom extension 'EventGridExtensionConfig'
[11/10/2017 4:32:34 PM] Generating 1 job function(s)
[11/10/2017 4:32:34 PM] Starting Host (HostId=oshidevdw1012-332967204, Version=1.0.11351.0, ProcessId=8524, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[11/10/2017 4:32:34 PM] Found the following functions:
[11/10/2017 4:32:34 PM] ExampleApp.Function1.Run
[11/10/2017 4:32:34 PM]
[11/10/2017 4:32:34 PM] Job host started
[11/10/2017 4:32:35 PM] Executing HTTP request: {
[11/10/2017 4:32:35 PM] "requestId": null,
[11/10/2017 4:32:35 PM] "method": "GET",
[11/10/2017 4:32:35 PM] "uri": "/"
[11/10/2017 4:32:35 PM] }
[11/10/2017 4:32:35 PM] Executed HTTP request: {
[11/10/2017 4:32:35 PM] "requestId": "fd683b48-be98-4ee4-8be3-2a2c56a2b970",
[11/10/2017 4:32:35 PM] "method": "GET",
[11/10/2017 4:32:35 PM] "uri": "/",
[11/10/2017 4:32:35 PM] "authorizationLevel": "Anonymous"
[11/10/2017 4:32:35 PM] }
[11/10/2017 4:32:35 PM] Response details: {
[11/10/2017 4:32:35 PM] "requestId": "fd683b48-be98-4ee4-8be3-2a2c56a2b970",
[11/10/2017 4:32:35 PM] "status": "OK"
[11/10/2017 4:32:35 PM] }

Http Functions:

    Function1: http://localhost:7071/api/Function1

Debugger listening on [::]:5858

You can see that the function is running on port 7071 and not on our custom 7072

If you start another function app with "LocalHttpPort": 7073 set as the setting you will get the error message

HTTP could not register URL http://localhost:7071/. Another application has already registered this URL with HTTP.SYS.

Attached is a basic repo using the same steps listed above.
ExampleApp.zip

@ahmelsayed
Copy link

can you see if this works for you

from my reply on https://stackoverflow.com/a/44977350/3234163

the command line takes precedence over the settings file, the problem is that VS passes an explicit port on the command line.

work around is to go through project -> properties -> Debug, then under Application arguments take control of the args. you can type host start --pause-on-error

pkhvf

@leftler
Copy link
Author

leftler commented Nov 10, 2017

@ahmelsayed Thank you for the work around! It works.

I am still going to leave this ticket open because I feel running a function app from within visual studio should be respecting that setting. Maybe it should check the local.settings.json file and if the host is defined don't pass in a port to func

@ahmelsayed
Copy link

Awesome! thank you for confirming. I'll close this issue then.

@leftler
Copy link
Author

leftler commented Nov 10, 2017

@ahmelsayed I spoke too soon, the the problem still persist just with a different part. The debugging port is now in use. The second program to start fails with

Error: listen EADDRINUSE :::5858
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Agent.Server._listen2 (net.js:1258:14)
at listen (net.js:1294:10)
at net.js:1404:9
at _combinedTickCallback (internal/process/next_tick.js:83:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

Please reopen the ticket.

@ahmelsayed ahmelsayed reopened this Nov 10, 2017
@ahmelsayed
Copy link

you can change that port by specifying --nodeDebugPort 5859. We should expose all these settings to local.settings.json as well for more consistency. You can open an issue over here https://github.com/Azure/azure-functions-cli/issues for that.

@leftler
Copy link
Author

leftler commented Nov 10, 2017

Setting the port fixed the issue, I have opened a issue on the cli repo about getting it added to local.settings.json (and helped someone who was having the same problem in their issue tracker too)

@Mike-E-angelo
Copy link

Mike-E-angelo commented Mar 21, 2018

OK I am confused here, please help me out. Why have a setting for LocalHttpPort if it isn't used? Should the documentation be updated?

@Mike-E-angelo
Copy link

Additionally, setting host start --pause-on-error results in the following exception:

Microsoft.DotNet.Cli.Utils.CommandUnknownException: 'No executable found matching command "dotnet-host"'

@ggailey777
Copy link
Contributor

ggailey777 commented Mar 22, 2018

@ahmelsayed can you address the issue that @Mike-EEE is reporting when trying to use the host start --pause-on-error workaround?

@pragnagopa
Copy link
Member

This is a known issue. Please see here for the workaround

@pragnagopa
Copy link
Member

Apologies closed too soon.

@ahmelsayed
Copy link

@Mike-EEE I'm assuming you're running v2? this issue was for v1. There are some differences in how VS loads things between the 2.

@Mike-E-angelo
Copy link

Great! I am not sure how I didn't see that post in all my searching. That is exactly what I was looking for...thank you, team! Please feel free to close this issue. :)

@ggailey777
Copy link
Contributor

Closing again per customer request.

@s-KaiNet
Copy link

s-KaiNet commented Apr 13, 2018

Hey guys, how to use https with functions? I've tried host start --pause-on-error with additional --useHttps parameter, however it fails with
The host is taking longer than expected to start.
I'm using v1 functions

@ahmelsayed
Copy link

@s-KaiNet can you try running this command outside of visual studio and see if it works there?

%UserProfile%\AppData\Local\Azure.Functions.Cli\1.0.10\func.exe host start --port <yourPort> --useHttps

the first time you run this it needs to ask for elevation to register the urlacls with https.sys.

Alternatively you can also run

netsh http show sslcert 0.0.0.0:<yourPort> #default 7071

You should see something like

SSL Certificate bindings:
-------------------------

    IP:port                      : 0.0.0.0:7071
    Certificate Hash             : 1b85aea76b6202df2fef8dd3418c8e20cde24e39
    Application ID               : {02639d71-0935-35e8-9d1b-9dd1a2a34627}
    Certificate Store Name       : MY
    Verify Client Certificate Revocation : Enabled
    Verify Revocation Using Cached Client Certificate Only : Disabled
    Usage Check                  : Enabled
    Revocation Freshness Time    : 0
    URL Retrieval Timeout        : 0
    Ctl Identifier               : (null)
    Ctl Store Name               : (null)
    DS Mapper Usage              : Disabled
    Negotiate Client Certificate : Disabled
    Reject Connections           : Disabled
    Disable HTTP2                : Not Set
    Disable QUIC                 : Not Set
    Disable TLS1.3               : Not Set
    Disable OCSP Stapling        : Not Set

If you don't, you can run this internal CLI command yourself to register the cert with http.sys from an elevated cmd using

func internal-use --actions 3 --port <yourPort> --protocol https

@ahmelsayed
Copy link

You can see what this command does here

func internal-use --actions 3 --port <yourPort> --protocol https

It generates a self-signed cert for localhost, adds it to your cert store then runs

netsh http add sslcert ipport=0.0.0.0:<yourPort> certhash=<the cert thumbprint>  certstorename=My appId=02639d71-0935-35e8-9d1b-9dd1a2a34627

@s-KaiNet
Copy link

self-cert is the cause of the issue indeed.
After investigating it deeply, I found that cli can't generate self-signed cert in my system and returns error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'CERTENROLLLib.CX509PrivateKey'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{728AB362-217D-11DA-B2A4-000E7BBB2B09}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I beleive I should create an issue in func-core cli repository...

@ahmelsayed
Copy link

Can you please open an issue here https://github.com/Azure/azure-functions-core-tools/issues
Also include your os version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants