Skip to content

Commit

Permalink
Fix unexpected unlock (#2221)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Oct 25, 2023
1 parent 1f779af commit 787f0b6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 0 additions & 2 deletions snow/networking/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ func (h *handler) selectStartingGear(ctx context.Context) (common.Engine, error)
func (h *handler) Start(ctx context.Context, recoverPanic bool) {
gear, err := h.selectStartingGear(ctx)
if err != nil {
h.ctx.Lock.Unlock()

h.ctx.Log.Error("chain failed to select starting gear",
zap.Error(err),
)
Expand Down
38 changes: 38 additions & 0 deletions snow/networking/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,41 @@ func TestDynamicEngineTypeDispatch(t *testing.T) {
})
}
}

func TestHandlerStartError(t *testing.T) {
require := require.New(t)

ctx := snow.DefaultConsensusContextTest()
resourceTracker, err := tracker.NewResourceTracker(
prometheus.NewRegistry(),
resource.NoUsage,
meter.ContinuousFactory{},
time.Second,
)
require.NoError(err)

handler, err := New(
ctx,
validators.NewManager(),
nil,
time.Second,
testThreadPoolSize,
resourceTracker,
nil,
subnets.New(ctx.NodeID, subnets.Config{}),
commontracker.NewPeers(),
)
require.NoError(err)

// Starting a handler with an unprovided engine should immediately cause the
// handler to shutdown.
handler.SetEngineManager(&EngineManager{})
ctx.State.Set(snow.EngineState{
Type: p2p.EngineType_ENGINE_TYPE_SNOWMAN,
State: snow.Initializing,
})
handler.Start(context.Background(), false)

_, err = handler.AwaitStopped(context.Background())
require.NoError(err)
}

0 comments on commit 787f0b6

Please sign in to comment.