zentol commented on a change in pull request #14432: URL: https://github.com/apache/flink/pull/14432#discussion_r547845925
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/JobManagerRunnerImpl.java ########## @@ -337,12 +337,25 @@ private void startJobMasterServiceSafely(UUID leaderSessionId) { checkState(jobMasterService == null, "JobMasterService must be null before being started."); try { - jobMasterService = jobMasterServiceFactory.createJobMasterService( + final JobMasterService newJobMasterService = jobMasterServiceFactory.createJobMasterService( jobGraph, new JobMasterId(leaderSessionId), this, userCodeClassLoader, initializationTimestamp); + + jobMasterService = newJobMasterService; + + jobMasterService.getTerminationFuture().whenComplete((unused, throwable) -> { + if (throwable != null) { + synchronized (lock) { + // check that we are still running and the valid JobMasterService Review comment: ```suggestion // check that we are still running and JobMasterService is still valid ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org