Framework lifecycle
ServiceGenerated::start / stopC++ userver lifecycle
userver task-based makers, ordered activation, and ownership-safe timeout handling.
When to use
Use this page when implementing maker hooks, owning resources, or diagnosing startup and shutdown.
Behavior
serviceInit,initMakers, andcustomMakersInitprecedeinitRuntime.- Infrastructure and function makers run as named userver async tasks; first failure requests cancellation and is rethrown.
ServiceApp::startstarts execution runtime and activates lifecycle categories in dependency order.- Stop closes DataSources and Components, drains graph execution, then stops DataSinks.
- After
ServiceApp::stop, generated connector, endpoint, binding, stream, and function views are cleared.
C++ userver startup sequence
ConfigurationLoad graph configResolve typed service, stream, connector, and endpoint settings.
FactoriesinitMakersInstall defaults, then run
customMakersInit and serviceStarted.ConstructionInvoke makers onceCreate infrastructure and long-lived functions in parallel.
BindingBuild graph and endpointsBind streams, callers, endpoint consumers, functions, and transport routes.
Connector coreOpen clientsStart managed connector clients before anything can submit or poll.
DownstreamStart graph resourcesStart storage, pools, components, and Sinks before inbound work.
Worker admissionStart managed pollingOpen Temporal or other connector-owned inbound workers after Sinks are ready.
SourcesStart DataSourcesOpen ordinary graph admission only after every downstream dependency is ready.
ServersStart listenersOpen generated HTTP and gRPC listeners after endpoint bindings and graph resources are ready.
C++ userver shutdown sequence
SignalStop requestedCreate one deadline from
shutdownTimeout.NetworkClose listenersReject new HTTP/gRPC requests and drain accepted handlers while graph dependencies remain alive.
SourcesDrain root workStop ordinary DataSources and admission-aware components.
WorkersStop managed admissionStop connector-owned polling only after ordinary Sources have drained.
ProducersPools, timers, storageStop admission and drain tasks that can still create graph work.
GraphParallelCall registryDrain only after no producer can create another child.
OutputStop DataSinksFlush results and accepted outbound submissions.
Connector coreClose clientsRelease managed connector clients after Sources, graph work, and Sinks no longer need them.
ReleaseRelease graph ownershipDrop endpoint consumers, streams, functions, and bindings only after their callbacks cannot run.
TelemetryFlush diagnosticsMetrics, traces, and logs cover shutdown and stop at the final safe boundary.
Context::bounded(shutdownTimeout)supplies the shared deadline.- DataSources and Components close root admission first.
- PriorityTaskPool, TaskPool, DelayPool, and Storage stop before
drainExecutionRuntimeobserves graph counters. - DataSinks remain alive until graph drain.
- Timed-out graph ownership is preserved to avoid dangling callbacks.
releaseRuntimeclears generated construction views only after the ServiceApp lifecycle has stopped runtime-owned objects.
Hooks and boundaries properties
Generated extension points and runtime-owned lifecycle boundaries.
PropertyTypeDescription
initMakersgeneratedAssigns asynchronous maker callables.
customMakersInitvirtual hookOverrides defaults before maker tasks.
initRuntimegeneratedMakes objects, builds graph, and registers lifecycle entries.
serviceStarteduser hookRuns after ServiceApp startup.
serviceStoppingnoexcept user hookRuns once before ServiceApp::stop; failures are logged and cannot escape the generated destructor.
stopruntimeIdempotent and called by the destructor.
Lifecycle outline
configure -> make once -> bind -> start -> admit -> drain -> stop