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

Remove context error check in lifecycle #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 2 additions & 9 deletions internal/lifecycle/lifecycle.go
Expand Up @@ -30,10 +30,11 @@ import (
"sync"
"time"

"go.uber.org/multierr"

"go.uber.org/fx/fxevent"
"go.uber.org/fx/internal/fxclock"
"go.uber.org/fx/internal/fxreflect"
"go.uber.org/multierr"
)

// Reflection types for each of the supported hook function signatures. These
Expand Down Expand Up @@ -203,11 +204,6 @@ func (l *Lifecycle) Start(ctx context.Context) error {
}()

for _, hook := range l.hooks {
// if ctx has cancelled, bail out of the loop.
if err := ctx.Err(); err != nil {
return err
}

if hook.OnStart != nil {
l.mu.Lock()
l.runningHook = hook
Expand Down Expand Up @@ -285,9 +281,6 @@ func (l *Lifecycle) Stop(ctx context.Context) error {
// Run backward from last successful OnStart.
var errs []error
for ; l.numStarted > 0; l.numStarted-- {
if err := ctx.Err(); err != nil {
return err
}
hook := l.hooks[l.numStarted-1]
if hook.OnStop == nil {
continue
Expand Down
11 changes: 7 additions & 4 deletions internal/lifecycle/lifecycle_test.go
Expand Up @@ -31,13 +31,14 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"go.uber.org/multierr"

"go.uber.org/fx/fxevent"
"go.uber.org/fx/internal/fxclock"
"go.uber.org/fx/internal/fxlog"
"go.uber.org/fx/internal/fxreflect"
"go.uber.org/fx/internal/testutil"
"go.uber.org/goleak"
"go.uber.org/multierr"
)

func testLogger(t *testing.T) fxevent.Logger {
Expand Down Expand Up @@ -126,8 +127,10 @@ func TestLifecycleStart(t *testing.T) {

l := New(testLogger(t), fxclock.System)
l.Append(Hook{
OnStart: func(context.Context) error {
assert.Fail(t, "this hook should not run")
OnStart: func(ctx context.Context) error {
if err := ctx.Err(); err != nil {
return err
}
return nil
},
OnStop: func(context.Context) error {
Expand Down