Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove extraneous error logs in lifecycle deadline exceed errors (#1005)
When running lifecycle hooks, it's possible they fail due to context deadline exceeded errors. Fx currently reports this error with a sorted list of all the hooks that have ran. This was added because it was difficult to debug which hook caused the context deadline error to occur. Now that every hook that is run emits an associated fxevent ( OnStartExecuting, OnStartExecuted, OnStopExecuting, OnStartExecuted), this error wrapping is no longer necessary. Example console output prior to this change: ``` [Fx] PROVIDE int <= fx.Annotate(main.main.func1() [Fx] PROVIDE string <= fx.Annotate(main.main.func3() [Fx] PROVIDE fx.Lifecycle <= go.uber.org/fx.New.func1() [Fx] PROVIDE fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm() [Fx] PROVIDE fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm() [Fx] INVOKE main.main.func5() 1 [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1.1() executing (caller: go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1) [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1.1() called by go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1 ran successfully in 15.917µs [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1.1() executing (caller: go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1) [Fx] ERROR Failed to start: OnStart hook added by go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1 failed: context deadline exceeded go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1.1() took 15.917µs from: go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1 (/Users/sungyoon/go/pkg/mod/go.uber.org/fx@v1.18.1/annotated.go:445) OnStart hook added by go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1 failed: context deadline exceeded go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1.1() took 15.917µs from: go.uber.org/fx.(*lifecycleHookAnnotation).Build.func1 (/Users/sungyoon/go/pkg/mod/go.uber.org/fx@v1.18.1/annotated.go:445) ``` The same error after this change: ``` ❯ go run main.go [Fx] PROVIDE int <= fx.Annotate(main.main.func1() [Fx] PROVIDE string <= fx.Annotate(main.main.func3() [Fx] PROVIDE fx.Lifecycle <= go.uber.org/fx.New.func1() [Fx] PROVIDE fx.Shutdowner <= go.uber.org/fx.(*App).shutdowner-fm() [Fx] PROVIDE fx.DotGraph <= go.uber.org/fx.(*App).dotGraph-fm() [Fx] INVOKE main.main.func5() 1 [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1.1() executing (caller: go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1) [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1.1() called by go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1 ran successfully in 9.292µs [Fx] HOOK OnStart go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1.1() executing (caller: go.uber.org/fx.(*lifecycleHookAnnotation).buildHookInstaller.func1) [Fx] ERROR Failed to start: context deadline exceeded context deadline exceeded ``` As shown above, the fxevent logs provide enough context for users to debug any issues from context deadline errors: hooks that were executed successfully, and hook that was attempted to execute before context was cancelled. Fixes #999
- Loading branch information