Closed
Description
Affects: Spring Boot 3.3.0, but I think every version supporting CRaC is affected
Consider the following simple application:
@SpringBootApplication
@EnableScheduling
class MyApp
fun main(args: Array<String>) {
runApplication<MyApp>(*args)
}
@RestController
class SchedulingController {
val data = AtomicInteger(0)
@Scheduled(timeUnit = TimeUnit.SECONDS, fixedRate = 1L)
fun increment(){
println(data.incrementAndGet())
}
@GetMapping("/")
fun data() = data.get()
}
My actions are following
./gradlew build
- Build with the following Dockerfile (
docker build -t last_edit_pre .
):
FROM bellsoft/liberica-runtime-container:jdk-crac-slim
ADD build/libs/last_edit-0.0.1-SNAPSHOT.jar /app/app.jar
WORKDIR /app
ENTRYPOINT java -XX:CRaCCheckpointTo=/app/checkpoint -jar /app/app.jar
- Run it with
docker run --privileged -p 8081:8080 -it --name last_edit_pre last_edit_pre:latest
and wait for some time (for example, until count 10) - Create a snapshot with
docker exec -it last_edit_pre jcmd 129 JDK.checkpoint
- Commit the snapshot to new image
docker commit last_edit_pre last_edit_post
- Run the newly-created image like this
docker run -it --rm --entrypoint java last_edit_post:latest -XX:CRaCRestoreFrom=/app/checkpoint
Here I observe an interesting behavior: Counter very quickly rewinds from the checkpoint moment to current time. The later I restore from the snapshot the more iterations it quickly rewinds.
It is potentially dangerous: if the scheduled operation is CPU-intensive of performs a dangerous operation - it can actually crush the application with all range of causes.
I do realize that sometimes this behavior might be required, in this case it should probably be an application property.