package host import ( "context" "time" "github.com/carlosframework/platform/internal/activator" ) func joinAgentShutdown(seedCtx context.Context, seedCancel context.CancelFunc, seedServer *filesSeedServer, cancelStartup context.CancelFunc, startupDone, dutiesDone <-chan struct{}) (context.Context, context.CancelFunc, error) { base := context.Background() cancel := func() {} if seedCtx != nil { base, cancel = activator.CleanupContext(base, 60*time.Second) } cancelStartup() if seedCtx != nil { seedCancel() join, stop := activator.CleanupContext(seedCtx, 30*time.Second) err := seedServer.close(join) stop() if err != nil { return base, cancel, err } } join, stop := context.WithTimeout(base, 5*time.Second) defer stop() joinAgentStartup(join, startupDone) joinAgentStartup(join, dutiesDone) if seedCtx == nil { // Main starts this clock after joining startup duties. base, cancel = context.WithTimeout(context.Background(), 60*time.Second) } return base, cancel, nil }