diff --git a/snow/networking/handler/handler.go b/snow/networking/handler/handler.go index a9d94e449288..1a9a1d89b6ae 100644 --- a/snow/networking/handler/handler.go +++ b/snow/networking/handler/handler.go @@ -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), ) diff --git a/snow/networking/handler/handler_test.go b/snow/networking/handler/handler_test.go index bcc465a94335..c28da4bc8b71 100644 --- a/snow/networking/handler/handler_test.go +++ b/snow/networking/handler/handler_test.go @@ -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) +}