Skip to content

using parent context to sequencer services shutdown #297

@lucasmenendez

Description

@lucasmenendez

regarding the Stop comments: i believe we can simplify (and clarify) the whole startup/cleanup of services using context. it would require a small refactor but i think it's worth it.
right now we have this in prod

// shutdownServices gracefully shuts down all services
func shutdownServices(services *Services) {
if services == nil {
return
}
// Stop services in reverse order of startup
if services.Sequencer != nil {
services.Sequencer.Stop()
}
if services.API != nil {
services.API.Stop()
}
if services.CensusDownloader != nil {
services.CensusDownloader.Stop()
}
if services.ProcessMon != nil {
services.ProcessMon.Stop()
}
services.TxManager.Stop() // Stop transaction manager
services.Storage.Close() // Close storage last
}

and even this in tests

// Create a combined cleanup function
cleanup := func() {
seqCancel()
api.Stop()
stateSync.Stop()
cd.Stop()
pm.Stop()
vp.Stop()
stg.Close()
c3cleanup()
web3Cleanup()
}

but those funcs just basically do a ctx.Cancel, can't we just handle that through the parent context anyway?

sequencer creates a single parent context, where all those services live. (test setup follows a similar pattern, obviously)

// Create context with cancellation for graceful shutdown
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Setup services
services, err := setupServices(ctx, cfg)
if err != nil {

cancelling the parent context, cancels all derived contexts.
and whatever cleanup needed, could simply happen on <-ctx.Done

Originally posted by @altergui in #284 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions