Skip to content

Provide a constant for graceful shutdown's smart lifecycle phase #24255

Closed
@joca-bt

Description

@joca-bt

Upon graceful shutdown the application will wait for a configurable timeout before killing the webserver and continuing with the termination of the rest of the application. Graceful shutdown is currently happening after ContextClosedEvent is published and before beans are destroyed, during lifecycle stop.

Our application publishes information about all serviced requests to an external data source. We're typically not interested in the requests that were terminated inflight by the graceful shutdown but are interested in the ones that finished after the shutdown was triggered. The logger publishing this information is async and we would like to flush it after the webserver has finished servicing all live requests and has been terminated and only then terminate the logger.

Currently we can achieve this with a SmartLifecycle bean whose phase is later than that of bean webServerGracefulShutdown. Bean webServerGracefulShutdown has the default phase but this is not documented and the class is not public, so this feels a bit hacky. Alternatively, we could terminate our logger on ContextClosedEvent. However, this way we would be dropping the logging of all the requests that finished being serviced during graceful shutdown.

There's a WebServerInitializedEvent. Would having a similar event for termination make sense?

I think @PreDestroy would also be an option but I'm not sure it might be the desired interface in this or similar situations.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions