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 Locally #892

Closed
nextdynamic opened this issue Jan 7, 2019 · 28 comments
Closed

Running Locally #892

nextdynamic opened this issue Jan 7, 2019 · 28 comments
Milestone

Comments

@nextdynamic
Copy link

running locally

@ejizba
Copy link
Member

ejizba commented Jan 8, 2019

@nextdynamic do you have the func cli installed? I'm not seeing any output when it's running func host start, etc.

What do you get if you run func --version?

How did you create your project?

@ejizba ejizba mentioned this issue Jan 8, 2019
@nextdynamic
Copy link
Author

nextdynamic commented Jan 8, 2019 via email

@ericdrobinson
Copy link

ericdrobinson commented Jan 9, 2019

@EricJizbaMSFT I'm running into the same[?] issue and decided that I would post here rather than start up a new thread.

Things were working A-OK until sometime yesterday when attempts to run the function using the built-in Task "Attach to Python Functions", well, stopped working.

When I attempt to run the function, I get the following output:

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.3.199 Commit hash: fdf734b09806be822e7d946fe17928b419d8a289)
Function Runtime Version: 2.0.12246.0
Skipping 'AzureWebJobsStorage' from local settings as it's already defined in current environment variables.
[1/9/19 4:04:04 PM] Shuttingdown Rpc Channels Manager
[1/9/19 4:04:04 PM] Stopping host...
[1/9/19 4:04:04 PM] Host shutdown completed.
Cannot access a disposed object.
Object name: 'IServiceProvider'.
Application is shutting down...

Here is a screenshot version, included for the pretty colors:
image

I should also mention that the process of "shutting down" never completes. I either have to kill the "func" process in Activity Monitor (or command line equivalent) or kill the terminal that the func is run in (trashcan icon in VS Code).

Any idea as to what's going on here? I would love to be able to test my Function locally as the current workflow of having to upload a ~230MB zip file before checking each change is... not great.

@FlippieCoetser
Copy link

@ericdrobinson
I did some investigation and found the following:

When starting a debug session: Clicking on the play button.
The following commands are executed in sequence:

  1. func extensions install
  2. pip install -r requirements.txt
  3. func host start

Rather than starting a debug session, I executed each command manually in sequence.

  1. func extensions install (Completes Successfully)
  2. pip install -r requirements.txt (Completes Successfully)
  3. func host start (Fails with the same results as in your screen shot aboe)

As a workaround I tried adjusting command 3. and that worked for me:
3. func host start --port 5860

I am not sure where one can set this port to be used for the vs code debugger.
The obvious limitations of this workaround is also that your cannot inspect or watch variables in VS Code.

Hope this narrows the problem down a bit.

@ericdrobinson
Copy link

@FlippieCoetser Thanks for the helpful pointers! Based on your findings, I ran some tests and found that I could change the VSCode Tasks (tasks.json) and Launch (launch.json) settings to use a different port than the default one. This allowed the system to get up and running.

However, when I attempted to hit up the localhost endpoint to test the HttpTrigger in the example, the browsers would simply spin for a while.

This lead me to run the following command to see who was actively listening on the default port (I'm on macOS 10.14.2):

lsof -nP -i4TCP:7071 | grep LISTEN

The result was: python3.6 [pid]. I then killed the pid associated with that python3.6 process, reset the modifications I made to the ports in the VSCode Tasks and Launch files and ran the "Attach to Python Functions" debug task again.

Everything worked.

It seems that occasionally some [Python] process isn't shutting down properly. I don't recall what happened right before this issue occurred for me but I will keep an eye out for it and report any findings!

@ejizba
Copy link
Member

ejizba commented Jan 10, 2019

It seems that occasionally some [Python] process isn't shutting down properly.

Yeah I've occasionally seen this, too. It seems like there's an existing issue in the func cli to track: Azure/azure-functions-core-tools#907

@nextdynamic can you confirm if you were seeing the same problem as @FlippieCoetser and @ericdrobinson or was yours different?

@ericdrobinson
Copy link

Ahh, good find! Seems that it's not limited to Python, either. Thanks for the pointer!

@nextdynamic
Copy link
Author

nextdynamic commented Jan 10, 2019 via email

@FlippieCoetser
Copy link

@nextdynamic this morning I did more testing.

Background

launch.json contains the following configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Python Functions",
      "type": "python",
      "request": "attach",
      "port": 9091,
      "host": "localhost",
      "preLaunchTask": "runFunctionsHost"
    }
  ]
}

Note: preLaunchTask point to runFuncitonsHost

tasks.json contains the runFunctionsHost task for each os:

{
      "label": "runFunctionsHost",
      "type": "shell",
      "osx": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func extensions install && pip install -r requirements.txt && func host start"
      },
      "windows": {
        "command": "${config:azureFunctions.pythonVenv}\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start"
      },
      "linux": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func extensions install && pip install -r requirements.txt && func host start"
      },
      "isBackground": true,
      "options": {
        "env": {
          "languageWorkers__python__arguments": "-m ptvsd --host 127.0.0.1 --port 9091"
        }
      },
      "problemMatcher": "$func-watch"
    }

I am on windows, therefore
${config:azureFunctions.pythonVenv}\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start applies.

Note: within my configuraiotn ${config:azureFunctions.pythonVenv} = .env.

Test

  1. Using the terminal interface in VS Code, I execute the above task:
    .env\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start

Results: works without any errors, but obviously VS Code Debugger is not active.

  1. Launch the debugger from within VS Code, which automatically executes:
    .env\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start

Results: The same errors as described previously.

Conclusion 1

The workaround I previous described can be further simplied by not adding -- port 5860. Just execute runFunctionsHost manually using VS Code Terminal.

More Testing

I suspect the root cause has something to do with the Python Visual Studio Debugger engine ptvsd
image

If I manually execute languageWorkers__python__arguments : python -m ptvsd --host 127.0.0.1 --port 9091 using the termainal, I also get
image
The same message as using launching the debugger.

To resolve this manually I then proceeded to install pip install ptvsd using the phython envrionment activated by .env\\Scripts\\activate
Afterwhich I launch the debugger from within VS Code again.

Results: Error resolved
image

Conclusion 2

Installing ptvsd in the local environment fixed the problem for me.

@nextdynamic
Copy link
Author

nextdynamic commented Jan 11, 2019 via email

@nextdynamic
Copy link
Author

nextdynamic commented Jan 11, 2019 via email

@FlippieCoetser
Copy link

FlippieCoetser commented Jan 11, 2019

@nextdynamic what happens if you execute the runFunctionHost tasks manually using the terminal in VS Code? When I do so it also works but then no debugger...

@ericdrobinson
Copy link

ericdrobinson commented Jan 11, 2019

@nextdynamic I understand that you're running Windows and the macOS command line solution I suggested won't work for you.

A commenter in the other thread for this issue posted the Windows equivalent:

Awesome, thanks! In PowerShell this would be

Get-Process -Id (Get-NetTCPConnection -LocalPort 7071).OwningProcess | Stop-Process

Perhaps you could try running that command in PowerShell and see if it resolves the issue for you?

@nextdynamic
Copy link
Author

nextdynamic commented Jan 11, 2019 via email

@ejizba
Copy link
Member

ejizba commented Jan 11, 2019

@FlippieCoetser ptsvd should be installed to the virtual environment for you in most cases (unless you created the venv manually yourself). But we're actually getting rid of that requirement. Tracked by this issue: #821

@nextdynamic I'm not convinced you're actually having the same issue as the others. I think we need to see the entire output of running .env\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start in your VS Code

@nextdynamic
Copy link
Author

nextdynamic commented Jan 11, 2019 via email

@ejizba
Copy link
Member

ejizba commented Jan 11, 2019

I would take a look at these lines in particular. There seems to be something wrong with "HubwayEventHubTrigger":

[1/11/2019 9:56:20 PM] Error indexing method 'Functions.HubwayEventHubTrigger' 
[1/11/2019 9:56:20 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HubwayEventHubTrigger'. Microsoft.WindowsAzure.Storage: Settings must be of the form "name=value". 
[1/11/2019 9:56:20 PM] Function 'Functions.HubwayEventHubTrigger' failed indexing and will be disabled. 
[1/11/2019 9:56:20 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions 
(e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.). 

@nextdynamic
Copy link
Author

nextdynamic commented Jan 11, 2019 via email

@ejizba
Copy link
Member

ejizba commented Jan 17, 2019

The AzureWebJobsStorage setting in local.settings.json was not set. I fixed it, but no change…

I don't know what you mean by "no change". You'll have to copy the full logs here again.

@nextdynamic
Copy link
Author

nextdynamic commented Jan 17, 2019 via email

@ejizba
Copy link
Member

ejizba commented Jan 17, 2019

Is your source code on Github? Can I take a look? It still says "No job functions found." which means there's something wrong with your project. It doesn't recognize HubwayEventHubTrigger. You could also try creating your project again from scratch

@nextdynamic
Copy link
Author

nextdynamic commented Jan 17, 2019 via email

@nextdynamic
Copy link
Author

nextdynamic commented Jan 17, 2019 via email

@nextdynamic
Copy link
Author

nextdynamic commented Jan 17, 2019 via email

@julielerman
Copy link

julielerman commented Jan 19, 2019

This might be related. Im using

  • CLI 2.3.199
  • latest VS Code 1.30.2
  • Microsoft.NET.Sdk.Functions" Version="1.0.24".

This is a C# project, created by teh Azure Functions extension and edited.
In the default state, the project runs with no problems via func host start.
However if I add a webjobs extension (CosmosDB 3.0.3 in my case) along with an output parameter with a binding attribute, I can debug but not just run the app.
Here's the method sig:

   [FunctionName("HttpTriggerCSharp")]
            public static ActionResult Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]  HttpRequest req, 
             [CosmosDB(
               databaseName: "CSharpDatabase",
                 collectionName: "CSharpCollection",
                 ConnectionStringSetting = "MyCosmosDBConnection",
                 CreateIfNotExists=true)] out dynamic document,
             ILogger log)

With debug (F5 or using the debug icon in VS Code), the host lock lease acquired and I can run the new version of the app successfully - the data is also inserted into the database.

However if I use the CLI func host start or even func host start --build, it goes through all of the normal processes but after displaying the URL, instead of getting "host lock lease acquired", the app shuts down.

WORKAROUND:
If I run dotnet clean before running func host start, it works!

@ejizba
Copy link
Member

ejizba commented Jan 30, 2019

I think I've figured out what's going on with the original comment. By default we use the PowerShell separator between commands in your .vscode/tasks.json file. However, if your terminal.integrated.shell.windows setting in VS Code is set to cmd.exe you will see no output just like the screenshot in the first comment.

There are two workarounds:

  1. Change the PowerShell separator (;) to the cmd separator (&&) in your .vscode/tasks.json file.
  2. Change your terminal to PowerShell. See here for more info: https://code.visualstudio.com/docs/editor/integrated-terminal#_configuration

In the meantime, I will close this as a duplicate of #760. We want to remove our reliance on separators in the first place so that this issue doesn't happen. If anyone is still having problems (there's been a few different issues discussed in this thread), please file a separate issue so that we can track each one down individually.

@ejizba ejizba closed this as completed Jan 30, 2019
@ejizba
Copy link
Member

ejizba commented Jan 30, 2019

@nextdynamic please let me know if those workaround help (so that you at least get output). Like I said if you run into different problems, please file a separate issue. It took a while to track down the root problem, but thanks for being responsive!

@nextdynamic
Copy link
Author

nextdynamic commented Feb 4, 2019 via email

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

No branches or pull requests

5 participants