When I use devtools reloading on a reactive application (webflux) it results in much slower restart times.

Minimal reproducer is here It's a sample application returning a string response.

I don't know how to trigger devtools properly from the command line, so I do it from the IDE by changing a String value in the controller class.

You can run the app with: ./mvnw spring-boot:run and opening http://localhost:8080/greeting/Oleg.

The app starts very fast -- on my machine Started DemoApplication in 0.65 seconds (JVM running for 0.992).

When I trigger a reload, the app is stopping for 2s during the reload process. In the debug logs I see:

2022-01-21 21:15:15.545 DEBUG 96273 --- [       Thread-5] o.s.boot.devtools.restart.Restarter      : Stopping application
2022-01-21 21:15:15.545 DEBUG 96273 --- [       Thread-5] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed from ACCEPTING_TRAFFIC to REFUSING_TRAFFIC
2022-01-21 21:15:15.545 DEBUG 96273 --- [       Thread-5] onfigReactiveWebServerApplicationContext : Closing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5a555b15, started on Fri Jan 21 21:14:48 EET 2022
2022-01-21 21:15:15.550 DEBUG 96273 --- [       Thread-5] ySourcesPropertyResolver$DefaultResolver : Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
2022-01-21 21:15:17.691 DEBUG 96273 --- [       Thread-5] o.s.b.d.r.c.RestartClassLoader           : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@63aaaaf3

Closing at 15.545 and created new classloader at 15:17.691.

Affecter SpringBoot version is 2.6.3, it also reproduces on 3.0.0-M1.

Comment From: wilkinsona

Thanks very much for the sample, @shelajev. This is caused by the default two second shutdown quiet period of the ReactorResourceFactory. It can be set to zero using a system property -Dreactor.netty.ioShutdownQuietPeriod=0. This removes the two second delay:

2022-01-21 20:22:53.681 DEBUG 83595 --- [       Thread-8] onfigReactiveWebServerApplicationContext : Closing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@4e479084, started on Fri Jan 21 20:22:44 GMT 2022
2022-01-21 20:22:53.730 DEBUG 83595 --- [       Thread-8] o.s.b.d.r.c.RestartClassLoader           : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@2cc4e52b

Comment From: shelajev

Can this property be set to 0 (or a very small value close to 0, like 5ms) when devtools reload is enabled?

Comment From: shelajev

I can confirm that with the property specified I see no delay in reloading.

Comment From: philwebb

Can this property be set to 0 (or a very small value close to 0, like 5ms) when devtools reload is enabled?

Yes, I think we can have better defaults for this. We'll keep this one open to investigate that.

Comment From: mhalbritter

I found two ways of doing this:

  • Use a BeanPostProcessor to call setShutdownQuietPeriod(Duration.ZERO); on all ReactorResourceFactory beans
  • Use a ApplicationContextInitializer to set the system property reactor.netty.ioShutdownQuietPeriod to 0.

Which one would be the preferred solution? You can see both ways here: https://github.com/mhalbritter/spring-boot/commit/cda49b602845afec4033a032dcba32aa3ba2f3e4

Comment From: wilkinsona

Thanks for looking at this, @mhalbritter.

It's unfortunate that we can't set it by adding an entry to devtools-property-defaults.properties. If setting the quiet period is useful, and it appears that it is, I wonder if we should add a configuration property for it that's applied by the auto-configuration and can then be set to 0 by DevTools.

Comment From: mhalbritter

Ah, good idea. I'll look into this.

Comment From: mhalbritter

Created a PR: https://github.com/spring-projects/spring-boot/pull/33855

Not sure if we should release this as a patch release.

Comment From: mhalbritter

Superseded by #33855.