Why does Jenkins safeRestart not wait for job to finish? I have a simple pipeline job with a single stage:

timestamps {
    node ("jenkins-slave-small") {
            stage('Stage 1') {
                sh "echo 'stage2 echo'; sleep 500s"
            }
    }
}


I am testing whether or not /safeRestart waits for my pipeline to finish executing, but it seems like it's not. 

Logs:

[Pipeline] { (Stage 1)
[Pipeline] sh
+ echo stage2 echo
stage2 echo
+ sleep 500s
Resuming build at Thu Sep 26 18:14:18 UTC 2019 after Jenkins restart
Waiting to resume part of test-folder » test-pipeline-no-parallels #6: Finished waiting
Ready to run at Thu Sep 26 18:14:55 UTC 2019


Am I misunderstanding how /safeRestart is supposed to behave or is that the intended behaviour?
Jenkins pipeline jobs are designed to be serializable to disk, to increase durability (their words not mine). Therefore they are considered safe to be suspended. The only things you can do is either wrap your stages in functions with @NonCPS decorator or using properties make the jobs non-resumable after restart, but this will cause them to not be resumed after restart.

Also, restarting jenkins is not really a thing that happens all the time, so it might not be worth the effort to protect against.