radius-project / radius

Radius is a cloud-native, portable application platform that makes app development easier for teams building cloud-native apps.
https://radapp.io
Apache License 2.0
1.48k stars 94 forks source link

Panic in AppCore RP when creating existing environment in different resource group #6395

Open jkotalik opened 1 year ago

jkotalik commented 1 year ago

Bug information

Steps to reproduce (required)

Repro'd when running locally, but assume the same would happen elsewhere

 curl --location --request PUT 'http://localhost:8080/planes/radius/local/resourceGroups/localrp/providers/Applications.Core/environments/justin-aws-env?api-version=2022-03-15-privatepreview'

When I already had an environment in resourceGroups/justin-aws

Causing the following panic

{"level":"info","ts":1667491622.475853,"logger":"applications.core.Applications.Core","caller":"middleware/recoverer.go:25","msg":"recovering from panic runtime error: invalid memory address or nil pointer dereference: goroutine 1253 [running]:\nruntime/debug.Stack()\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/runtime/debug/stack.go:24 +0x64\ngithub.com/project-radius/radius/pkg/middleware.Recoverer.func1.1()\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/middleware/recoverer.go:24 +0x7c\npanic({0x104e2bf40, 0x10613e240})\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/runtime/panic.go:844 +0x26c\ngithub.com/project-radius/radius/pkg/corerp/frontend/controller/environments.(*CreateOrUpdateEnvironment).Run(0x14003061280, {0x1051ac838, 0x14001293a70}, {0x10519cd60, 0x140017c46d8}, 0x140025f9200)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/corerp/frontend/controller/environments/createorupdateenvironment.go:96 +0x734\ngithub.com/project-radius/radius/pkg/armrpc/frontend/server.RegisterHandler.func1({0x10519cd60, 0x140017c46d8}, 0x140025f9200)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/armrpc/frontend/server/handler.go:53 +0x80\nnet/http.HandlerFunc.ServeHTTP(0x14000bf8660, {0x10519cd60, 0x140017c46d8}, 0x140025f9200)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/project-radius/radius/pkg/validator.APIValidator.func1.1({0x10519cd60, 0x140017c46d8}, 0x140025f9200)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/validator/apivalidator.go:60 +0x418\nnet/http.HandlerFunc.ServeHTTP(0x14002205480, {0x10519cd60, 0x140017c46d8}, 0x140025f9200)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/project-radius/radius/pkg/middleware.MetricsRecorder.func1.1({0x1051aaec0, 0x14000952540}, 0x140025f9200)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/middleware/metricsrecorder.go:28 +0xd8\nnet/http.HandlerFunc.ServeHTTP(0x140022054e0, {0x1051aaec0, 0x14000952540}, 0x140025f9200)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/project-radius/radius/pkg/armrpc/servicecontext.ARMRequestCtx.func1.1({0x1051aaec0, 0x14000952540}, 0x140025f9200)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/armrpc/servicecontext/middleware.go:34 +0x288\nnet/http.HandlerFunc.ServeHTTP(0x1400194d680, {0x1051aaec0, 0x14000952540}, 0x140025f9100)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/project-radius/radius/pkg/middleware.AppendLogValues.func1({0x1051aaec0, 0x14000952540}, 0x140025f9100)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/middleware/appendlogger.go:36 +0x2e8\nnet/http.HandlerFunc.ServeHTTP(0x140017c4690, {0x1051aaec0, 0x14000952540}, 0x140025f9000)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/project-radius/radius/pkg/middleware.Recoverer.func1({0x1051aaec0, 0x14000952540}, 0x140025f9000)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/middleware/recoverer.go:38 +0xb4\nnet/http.HandlerFunc.ServeHTTP(0x140017c46a8, {0x1051aaec0, 0x14000952540}, 0x140025f9000)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\ngithub.com/gorilla/mux.(*Router).ServeHTTP(0x1400031cb40, {0x1051aaec0, 0x14000952540}, 0x140025f9000)\n\t/Users/jukotali/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x25c\ngithub.com/project-radius/radius/pkg/middleware.LowercaseURLPath.func1({0x1051aaec0, 0x14000952540}, 0x140025f8d00)\n\t/Users/jukotali/go/src/github.com/project-radius/radius/pkg/middleware/lowercaseurlpath.go:17 +0xc8\nnet/http.HandlerFunc.ServeHTTP(0x14000bf9038, {0x1051aaec0, 0x14000952540}, 0x140025f8d00)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2084 +0x48\nnet/http.serverHandler.ServeHTTP({0x14000e79260}, {0x1051aaec0, 0x14000952540}, 0x140025f8d00)\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:2916 +0x424\nnet/http.(*conn).serve(0x14002e265a0, {0x1051ac790, 0x1400194d540})\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:1966 +0x1510\ncreated by net/http.(*Server).Serve\n\t/opt/homebrew/Cellar/go/1.18.4/libexec/src/net/http/server.go:3071 +0x800\n"}

System information

rad Version (required)

RELEASE VERSION BICEP COMMIT edge v0.14.0-46-g2a76f93 0.10.144 2a76f93a6d1713feab6c40c8bac00f323d4ecee6

Operating system (required)

MacOS M1

Additional context

AB#4836

ytimocin commented 1 year ago

I ran into the same issue late last night. It is caused by this line: https://github.com/project-radius/radius/blob/main/pkg/corerp/frontend/controller/environments/createorupdateenvironment.go#L107. Thanks for creating the issue. I was going to create it today after reproducing the bug. 😀