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

azd up fails with a go panic on a .NET Aspire using AddContainer #3070

Closed
1 task
shanselman opened this issue Dec 5, 2023 · 1 comment
Closed
1 task
Assignees
Labels

Comments

@shanselman
Copy link

shanselman commented Dec 5, 2023

Output from azd version
Run azd version and copy and paste the output here:

azd version 1.5.0 (commit 012ae73)

Describe the bug

azd up will cause a go panic if you run it on an .NET aspire starter template after adding these lines to AppHost's program.cs:

builder.AddContainer("podcast", "podcast", "latest")
   .WithServiceBinding(hostPort: 8080, containerPort: 80, scheme: "http")
   .WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
   .WithEnvironment("ASPNETCORE_URLS", "http://+:80");

It's perhaps that Aspire is generating something wrong, but either way, both sides (aspire generator and azd consumer) can be more defensive

Building...
info: Aspire.Hosting.Publishing.ManifestPublisher[0]
      Published manifest to: C:\Users\scottha\AppData\Local\Temp\azd-provision777714042\apphost-manifest.json
2023/12/05 14:47:41 hooks.go:156: service 'apiservice' does not require any command hooks.
2023/12/05 14:47:41 hooks.go:156: service 'webfrontend' does not require any command hooks.
2023/12/05 14:47:41 hooks.go:85: azd project is not available or does not contain any command hooks, skipping command hook registrations.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xa64ee1]

goroutine 1 [running]:
github.com/azure/azure-dev/cli/azd/pkg/apphost.(*infraGenerator).Compile(0xc0001ca7c0)
        github.com/azure/azure-dev/cli/azd/pkg/apphost/generate.go:409 +0x121
github.com/azure/azure-dev/cli/azd/pkg/apphost.BicepTemplate(0xc00059e190?)
        github.com/azure/azure-dev/cli/azd/pkg/apphost/generate.go:94 +0x17b
github.com/azure/azure-dev/cli/azd/pkg/project.(*DotNetImporter).ProjectInfrastructure(0xc00059e190?, {0x1251ec0?, 0xc00055bf50?}, 0xc00008fec0?)
        github.com/azure/azure-dev/cli/azd/pkg/project/dotnet_importer.go:97 +0x78
github.com/azure/azure-dev/cli/azd/pkg/project.(*ImportManager).ProjectInfrastructure(0xc00012c0e8, {0x1251ec0, 0xc00055bf50}, 0xc0000d1760)
        github.com/azure/azure-dev/cli/azd/pkg/project/importer.go:125 +0x447
github.com/azure/azure-dev/cli/azd/cmd.(*upAction).Run(0xc00014e1c0, {0x1251ec0, 0xc00055bf50})
        github.com/azure/azure-dev/cli/azd/cmd/up.go:117 +0x277
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x1251ec0?, 0xc00055bf50?})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:127 +0x2e8
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*HooksMiddleware).registerCommandHooks(0xc00059e1e0?, {0x1251ec0, 0xc00055bf50}, 0x410965?, 0xc000506c10?, 0xc00068a400)
        github.com/azure/azure-dev/cli/azd/cmd/middleware/hooks.go:88 +0x399
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*HooksMiddleware).Run(0xc00059e1e0, {0x1251ec0?, 0xc00055bec0?}, 0xc00068a400)
        github.com/azure/azure-dev/cli/azd/cmd/middleware/hooks.go:73 +0x1d8
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x1251ec0, 0xc00055bec0})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:125 +0x2a2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*TelemetryMiddleware).Run(0xc000506ad0, {0x1251ec0, 0xc0003a96e0}, 0xc00068a400)
        github.com/azure/azure-dev/cli/azd/cmd/middleware/telemetry.go:85 +0x8b8
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x1251ec0, 0xc0003a96e0})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:125 +0x2a2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*ExperimentationMiddleware).Run(0xc00003c450?, {0x1251ec0, 0xc0003a96e0}, 0xc00068a400)
        github.com/azure/azure-dev/cli/azd/cmd/middleware/experimentation.go:64 +0x4d6
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x1251ec0, 0xc0003a96e0})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:125 +0x2a2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*DebugMiddleware).Run(0xc0005a4300, {0x1251ec0, 0xc0003a96e0}, 0xc00068a400)
        github.com/azure/azure-dev/cli/azd/cmd/middleware/debug.go:48 +0x311
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x1251ec0, 0xc0003a96e0})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:125 +0x2a2
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction(0xc00045cc30, {0x1251ec0, 0xc0003a96e0}, 0xc00056da80?, {0x1246600?, 0xc00014e1c0})
        github.com/azure/azure-dev/cli/azd/cmd/middleware/middleware.go:131 +0x226
github.com/azure/azure-dev/cli/azd/cmd.(*CobraBuilder).configureActionResolver.func1(0xc000453400, {0xc00045f940?, 0x0, 0x1})
        github.com/azure/azure-dev/cli/azd/cmd/cobra_builder.go:142 +0x4cf
github.com/spf13/cobra.(*Command).execute(0xc000453400, {0xc00045f930, 0x1, 0x1})
        github.com/spf13/cobra@v1.3.0/command.go:856 +0x694
github.com/spf13/cobra.(*Command).ExecuteC(0xc0003d1680)
        github.com/spf13/cobra@v1.3.0/command.go:974 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.3.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(0x1251e88?, {0x1251e88?, 0x198c080?})
        github.com/spf13/cobra@v1.3.0/command.go:895 +0x47
main.main()
        D:/a/_work/1/s/cli/azd/main.go:61 +0x1fe

To Reproduce

Make a .NET 8 Aspire Starter app, and add these lines to Program.cs. This app will build and run fine, but azd up won't run.

builder.AddContainer("podcast", "podcast", "latest")
   .WithServiceBinding(hostPort: 8080, containerPort: 80, scheme: "http")
   .WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
   .WithEnvironment("ASPNETCORE_URLS", "http://+:80");

Expected behavior

I expect it at least try to deploy or throw a reasonable error.

Environment
Information on your environment:

  • CLI only

@davidfowl

@weikanglim weikanglim self-assigned this Dec 5, 2023
@weikanglim
Copy link
Contributor

This is a duplicate of #3016 which will be fixed with Aspire preview 2.

weikanglim added a commit that referenced this issue Dec 7, 2023
Avoid a panic and provide a better error message when containerPort is missing in binding. This is a runtime check for what should normally be handled at compile-time.

Related to: #3070
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

4 participants