motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.79k stars 317 forks source link

panic: runtime error with OAuth plugin #338

Closed jzyinq closed 6 years ago

jzyinq commented 6 years ago

Janus docker images fails randomly on startup while loading OAuth plugin.

I've checked both 3.7.2-rc.1 and 3.7.1-rc.21 images.

Reproduction Steps:

I've got this problem on our internal configuration, but it occurs also on front-proxy-auth example.

Just change image in docker-compose to one of listed above -> https://github.com/hellofresh/janus/blob/master/examples/front-proxy-auth/docker-compose.yml#L5 and run example.

After Janus starts it randomly fails with error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x90ad0f]

goroutine 1 [running]:
github.com/hellofresh/janus/pkg/proxy.(*Register).Add(0x0, 0xc4204bc860, 0x0, 0x0)
        /go/src/github.com/hellofresh/janus/pkg/proxy/register.go:59 +0x10f
github.com/hellofresh/janus/pkg/plugin/oauth2.(*OAuthLoader).registerRoutes(0xc420434110, 0xc4204ff400)
        /go/src/github.com/hellofresh/janus/pkg/plugin/oauth2/loader.go:123 +0x2fb
github.com/hellofresh/janus/pkg/plugin/oauth2.(*OAuthLoader).RegisterOAuthServers(0xc420434110, 0xc420434158, 0x1, 0x1, 0xce7460, 0xc420458f40)
        /go/src/github.com/hellofresh/janus/pkg/plugin/oauth2/loader.go:71 +0xd9
github.com/hellofresh/janus/pkg/plugin/oauth2.(*OAuthLoader).LoadDefinitions(0xc420434110, 0xce7460, 0xc420458f40)
        /go/src/github.com/hellofresh/janus/pkg/plugin/oauth2/loader.go:26 +0x7f
github.com/hellofresh/janus/pkg/plugin/oauth2.onStartup(0xbc9e00, 0xc42045d700, 0x0, 0x0)
        /go/src/github.com/hellofresh/janus/pkg/plugin/oauth2/setup.go:109 +0x517
github.com/hellofresh/janus/pkg/plugin.EmitEvent(0xc57a15, 0x7, 0xbc9e00, 0xc42045d700, 0x0, 0x0)
        /go/src/github.com/hellofresh/janus/pkg/plugin/plugin.go:95 +0x169
github.com/hellofresh/janus/pkg/server.(*Server).StartWithContext(0xc4204c0af0, 0xce6620, 0xc420464940, 0xc420464940, 0xc4204b0850)
        /go/src/github.com/hellofresh/janus/pkg/server/server.go:101 +0x297
github.com/hellofresh/janus/cmd.RunServerStart(0xce6660, 0xc42009a018, 0xc42042484e, 0x0, 0x0)
        /go/src/github.com/hellofresh/janus/cmd/server.go:83 +0x3c8
github.com/hellofresh/janus/cmd.NewServerStartCmd.func1(0xc42046c000, 0x12339e8, 0x0, 0x0, 0x0, 0x0)
        /go/src/github.com/hellofresh/janus/cmd/server.go:44 +0x3c
github.com/hellofresh/janus/vendor/github.com/spf13/cobra.(*Command).execute(0xc42046c000, 0x12339e8, 0x0, 0x0, 0xc42046c000, 0x12339e8)
        /go/src/github.com/hellofresh/janus/vendor/github.com/spf13/cobra/command.go:746 +0x468
github.com/hellofresh/janus/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc4200e78c0, 0xc4200e7d40, 0xc4200e7b00, 0xc42009a018)
        /go/src/github.com/hellofresh/janus/vendor/github.com/spf13/cobra/command.go:831 +0x2e4
github.com/hellofresh/janus/vendor/github.com/spf13/cobra.(*Command).Execute(0xc4200e78c0, 0x403dfc, 0xc42008e058)
        /go/src/github.com/hellofresh/janus/vendor/github.com/spf13/cobra/command.go:784 +0x2b
main.main()
        /go/src/github.com/hellofresh/janus/main.go:13 +0x2b

There is also another issue that with active oauth plugin in logs there are errors that it wasn't able to register endpoints because of lack of listen_path but it's not true.

{"level":"debug","listen_path":"","msg":"Registering OAuth endpoint","time":"2018-07-17T07:11:37Z"}
[StatsGo] 2018/07/17 07:11:37 Stats counter incremented metric=error-log.error.-.-
[StatsGo] 2018/07/17 07:11:37 Stats counter incremented metric=total.error-log
{"error":"proxy.listen_path is required","level":"error","listen_path":"","msg":"Error when registering endpoint","time":"2018-07-17T07:11:37Z"}
{"level":"debug","listen_path":"/auth/token","msg":"Registering OAuth endpoint","time":"2018-07-17T07:11:37Z"}
{"balancing_alg":"roundrobin","level":"debug","msg":"Using a load balancing algorithm","time":"2018-07-17T07:11:37Z"}

It occurs randomly but very often - after couple of restarts it works fine but it's a blocker to us cause we can't use timeout feature that you recently put out with this issue.

Expected behavior:

Running smoothly like it used to ;-)

Janus version: 3.7.2-rc.1 and 3.7.1-rc.21

vgarvardt commented 6 years ago

Thank you for reporting. I'll try to reproduce this and fix the issue.

jzyinq commented 6 years ago

I see you already got potential fix for this issue - looking forward for a new release with this fix.

Keep up the good work!

vgarvardt commented 6 years ago

@jzyinq I merged a fix - new RC will be available in minutes. I could reproduce the issue with front-proxy-auth and used it to identify the problem and then fix it - race condition issues is nearly impossible to reproduce in debug environment. After implementing the fix I was unable to reproduce the problem, so I hope it is really solved. If you'll find it is still here feel free to reopen the issue with some additional details.

Thank you for reporting!