Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In a context hierarchy, timeout-per-shutdown-phase is only honoured in the root context #22014

Closed
pszemus opened this issue Jun 18, 2020 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@pszemus
Copy link

pszemus commented Jun 18, 2020

Spring Boot 2.3.1

I've been playing around with the latest Spring Boot Graceful Shutdown feature and discovered that after adding spring-cloud-config-server, as a dependency, my Spring Boot application fails to use configured spring.lifecycle.timeout-per-shutdown-phase property and, instead, it's using the default 30s value for graceful shutdown timeout.

I've prepared a minimal application:
https://github.com/pszemus/graceful-shutdown-demo
that has configured graceful shutdown timeout of 8s: https://github.com/pszemus/graceful-shutdown-demo/blob/master/src/main/resources/application.yml#L5
After requesting the long lasting endpoint /greeting and stoping the application it should stop after 8 seconds, but it's stopping after 30 seconds, instead:

2020-06-18 16:02:59.629  INFO 31481 --- [extShutdownHook] o.s.b.w.e.tomcat.GracefulShutdown        : Commencing graceful shutdown. Waiting for active requests to complete
2020-06-18 16:03:29.631  INFO 31481 --- [extShutdownHook] o.s.c.support.DefaultLifecycleProcessor  : Failed to shut down 1 bean with phase value 2147483647 within timeout of 30000ms: [webServerGracefulShutdown]
2020-06-18 16:03:29.680  INFO 31481 --- [tomcat-shutdown] o.s.b.w.e.tomcat.GracefulShutdown        : Graceful shutdown aborted with one or more requests still active

Configured 8 seconds timeout is visible in /actuator/configprops, but apparently it's not used:

        "spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties": {
          "prefix": "spring.lifecycle",
          "properties": {
            "timeoutPerShutdownPhase": "PT8S"
          },
          "inputs": {
            "timeoutPerShutdownPhase": {
              "origin": "class path resource [application.yml]:5:37",
              "value": "8s"
            }
          }
        }

If one gets rid of spring-cloud-config-server from pom.xml: https://github.com/pszemus/graceful-shutdown-demo/blob/master/pom.xml#L22
then the application starts using configured 8s timeout:

C2020-06-18 15:54:13.934  INFO 30672 --- [extShutdownHook] o.s.b.w.e.tomcat.GracefulShutdown        : Commencing graceful shutdown. Waiting for active requests to complete
2020-06-18 15:54:21.937  INFO 30672 --- [extShutdownHook] o.s.c.support.DefaultLifecycleProcessor  : Failed to shut down 1 bean with phase value 2147483647 within timeout of 8000ms: [webServerGracefulShutdown]
2020-06-18 15:54:21.983  INFO 30672 --- [tomcat-shutdown] o.s.b.w.e.tomcat.GracefulShutdown        : Graceful shutdown aborted with one or more requests still active
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 18, 2020
@wilkinsona wilkinsona self-assigned this Jun 18, 2020
@wilkinsona
Copy link
Member

Thanks for the sample. When spring-cloud-config-server is added, it results in Spring Cloud creating a parent context that is configured in such a way that it does not include LifecycleAutoConfiguration. As a result, the parent context uses the default lifecycle processor with the default timeout. When LifecycleAutoConfiguration runs in the child context it backs off as it finds the lifecycle processor in the parent context so the main (child) context ends up creating a default lifecycle processor of its own with the default timeout.

We need to only check the current context for a bean named defaultLifecycleProcessor.

@wilkinsona wilkinsona changed the title timeout-per-shutdown-phase for graceful shutdown not used with spring-cloud-config-server on classpath In a context hierarchy, timeout-per-shutdown-phase is only honoured in the root context Jun 18, 2020
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 18, 2020
@wilkinsona wilkinsona added this to the 2.3.x milestone Jun 18, 2020
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.3.2 Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants